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

BrdgBldrAsked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.