Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call Open Common Dialog in Excel VBA

Status
Not open for further replies.

vb6novice

Programmer
Sep 23, 2002
288
US
Please tell me how to call the Open Common Dialog box in VBA code for Excel 97.

All help is greatly appreciated.
 
Thanks Doc. It works great. Now, how do I get the result of the the file selected when the user clicks Open?
 
Hi vb6
It might depend on what you want to do. Using the method Dr has suggested will open the file when you click open. You could then get the name using
Code:
ActiveWorkbook.Name
in the next line of code.

Another method you could use is 'GetOpenFilename'
eg
Code:
Sub a()
Dim sFile As String
sFile = Application.GetOpenFilename _
    ("Excel files (*.xls), *.xls", , "Select a File")
MsgBox sFile
End Sub

This doesn't open the file but returns the full path and file name. If you then want to open the file you need to use the open method. There is an example in this thread: thread707-603390

To get just the file name takes a little string manipulation
eg
Code:
MsgBox Right(sFile, Len(sFile) - InStrRev(sFile, "\"))

;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top