Consulting

Results 1 to 3 of 3

Thread: append variable to file path???

  1. #1

    Question append variable to file path???

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like this

    [vba]


    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
    [/vba]

    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    AWESOME!!!
    This worked perfectly. Thanks a lot!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •