I'm trying to run a macro that will open up a user-selected filename. I can successfully pass a filename into a function, as I show below, but apparently functions can't run Excel commands such as a workbook open. It passes the filename, but does not open it.
Function OpentheFile(TheFileName as String)
Workbooks.Open FileName:=TheFileName
End Function
So I tried using a Sub. If I directly input the filename like below, then the file opens.
Sub OpentheFile()
Workbooks.Open FileName:="C:\Documents\file.xls
End Sub
But I can't add parameters to pass into the Sub. It returns some indication of an invalid command when I do this.
So essentially what I want is to pass a Macro a filename, and the Macro to open it. Seems simple enough, but I can't figure it out. Thoughts?
Bookmarks