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
 
To show the file>open window use

Application.Dialogs(xlDialogOpen).Show
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top