Macro open a file in any drive/directory

  • Thread starter Thread starter Juan
  • Start date Start date
J

Juan

Hello,
I'm tryign to do a macro that will open a file. I want it
to bring up the Open File dialog, so that users can search
the file they want. Example, the file might be in any
drive and one user might call the file differently, so
need to be able for users to open the file.
I know there'' GetFile code, but can't figure right coding.

please advise any help.

thank you,

juan
 
You could have more control by using application.getopenfilename:

Option Explicit
Sub testme()

Dim myFileName As Variant
Dim myWkbk As Workbook

myFileName = Application.GetOpenFilename("Excel files, *.xls")
If myFileName = False Then
'user hit cancel
Exit Sub '??
End If

Set myWkbk = Workbooks.Open(Filename:=myFileName)

......

end sub

Lots more info in VBA's help.
 
Back
Top