Results 1 to 3 of 3

Thread: How to save a user selected file as a variable?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    23
    Location

    How to save a user selected file as a variable?

    In the middle of creating an application, and part of it is that a file will have to be loaded in. The file won't always be the same file, so I just have the folder location open up and let the user select the config file that will be used.

    Dim fopen As FileDialog
            Set fopen = Application.FileDialog(msoFileDialogOpen)
            fopen.Title = "Select Config File"
            fopen.InitialFileName = "C:\......"
            fopen.Show
    Is the current code I have and that works perfectly fine. It opens right up to the correct folder. I've tried a few different ways to get the file to save to a variable, but at the moment haven't had much luck. The file doesn't need to be displayed I just need it saved into a variable so I can manipulate it as needed.

        Dim fopen As FileDialog
        Dim fcontent As String
        Dim textfile As Integer
        
        Set fopen = Application.FileDialog(msoFileDialogOpen)
        fopen.Title = "Select Config File"
        fopen.InitialFileName = "C:...."
        fopen.Show
        textfile = FreeFile
        Open EvenLogDir & fopen For Input As #textfile
        fcontent = Input(LOF(textfile), textfile)
        
        Close #textfile
    I'm working with this, and now I'm getting a run-time error 53: File not Found. Not sure how I'm getting that as I'm clicking on the exact file for it to load it, so it should have the exact path.
    Last edited by Zuccj; 06-23-2017 at 09:19 AM.

Posting Permissions

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