+ Reply to Thread
Results 1 to 4 of 4

Open file based on user selection

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Open file based on user selection

    Greetings, Gurus.

    A search of the forum gave me most of the code I need, I just need some help with modification. The code below opens a window which allows the user to select a file to open. Apparently, it starts in the directory of the file containing the macro. How would I modify this to open in "M:\Archived PO Responses\Processed\"?
        On Error GoTo NoPO
        NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
        If NewFN = False Then
        'They pressed Cancel
        MsgBox "Stopping because you did not select a file"
        Exit Sub
        Else
        Workbooks.Open Filename:=NewFN
        End If
        On Error GoTo 0
    Thanks in advance for any help you can offer.

    Hutch
    Last edited by hutch@edge.net; 10-23-2008 at 11:23 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Found it! I just needed to add the ChDir line before the GetOpenFilename. Here's the code that worked:
        On Error GoTo NoPO
        ChDir "M:\Archived PO Responses\Processed\"
        NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
        If NewFN = False Then
        'They pressed Cancel
        MsgBox "Stopping because you did not select a file"
        Exit Sub
        Else
        Workbooks.Open Filename:=NewFN
        End If
        On Error GoTo 0
    Have a good one.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Okay, I was wrong. This isn't solved.

    Adding the ChDir line worked on my computer, but for some reason when I runt he macro on another computer, it still defaults to the My Computer directory when the select file dialog opens up. Is there another line I need to add, or what?

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    This worked on the other computer:
        ChDrive "M:\Archived PO Responses\Processed"
        ChDir "M:\Archived PO Responses\Processed"
        NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a file")
        If NewFN = False Then
        'They pressed Cancel
        MsgBox "Stopping because you did not select a file"
        Exit Sub
        Else
        Workbooks.Open Filename:=NewFN
        End If

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1