PDA

View Full Version : append variable to file path???



mushynator
01-23-2008, 03:07 PM
Hi, I am new to vba. This probably isn't hard at all for lot of you, but here is my problem.
I have the user input a name, then I add (using & sign) more characters to that name to make it a "fully qualified" file name. I then store the whole thing in a variable, let us say myFileName.
Next, I want to open this file, but I am not sure how to refer to a variable when using something like:
Workbooks.Open Filename:="C:\dir\myFileName"
Could someone please help?

Thanks

Bob Phillips
01-23-2008, 03:46 PM
Something like this




Dim mpFilename As String
Dim mpFullname As String

mpFilename = InputBox("Supply a filename")
If mpFilename <> "" Then

mpFullname = "C:\dir\" & mpFilename

Workbooks.Open filname:=mpFullname

'etc
End If


but personally, I would use GetOpenFilename to throw up a dialog and let them navigate to the file to open. GetOpenFilename returns the selected path and filename, so you still have to open it.

mushynator
01-23-2008, 03:56 PM
AWESOME!!!
This worked perfectly. Thanks a lot!!!