• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Excel VBA to define file open dialogue in default folder

I have successfully used this code on my machine, it correctly points to the folder on drive G: as defined in the code. However, on the machine of one of my colleagues, which has also a drive G:, the dialogue points to drive H: ???!!

how to fix it?

Sub OpenFileFromDefaultDirectory()
    ChDir "G:\data\"
    Application.SendKeys "mountain*{RETURN}"
    SourceWb = Application.GetOpenFilename("Excel Files (*.xls), *.xls") 'Allows for user to select file
    If SourceWb = False Then
        MsgBox "You didn't select a file!"
    Else
        Workbooks.Open SourceWb 'Open source workbook\
    End If
End Sub

Open in new window

0
BrdgBldr
Asked:
BrdgBldr
1 Solution
 
Rory ArchibaldCommented:
Try changing drive first:
Sub OpenFileFromDefaultDirectory()
   ChDrive "G:"
    ChDir "G:\data\"
    Application.SendKeys "mountain*{RETURN}"
    SourceWb = Application.GetOpenFilename("Excel Files (*.xls), *.xls") 'Allows for user to select file
    If SourceWb = False Then
        MsgBox "You didn't select a file!"
    Else
        Workbooks.Open SourceWb 'Open source workbook\
    End If
End Sub

Open in new window

0
 
BrdgBldrAuthor Commented:
rorya! again! it works! thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now