How To Open Excel File Using Macro
Imagine this condition; We are in the middle of doing something using Excel VBA macro, then we want the macro to automatically show the File Open dialog box to make us (user) able to choose another Excel file to be opened by Excel.
Got the picture? Below is vba procedure that do exactly like that, show the File Open dialog box, and open the Excel file selected by user.
Sub OpenExcelFile()
Dim vFile As Variant
'Showing Excel Open Dialog Form
vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
"*.xl*", 1, "Select Excel File", "Open", False)
'If Cancel then exit
If TypeName(vFile) = "Boolean" Then
Exit Sub
End If
'Open selected file
Workbooks.Open vFile
End Sub
Related Entries
External Resources
- Microsoft Excel 2003/2007 Video Tutorials
Step-by-step video guide to mastering Charts, PivotTable, Data Analysis and Macro programming in Microsoft Excel in 5 hours.
- 101 Secrets of Microsoft Excel
Discover 101 of Excels little-known secrets that have been hiding right under your nose.
Tagged with: Dialog Box, Open File
gary
Thanks this works great. Is there also way to have the macro open a specfic xls file?
Poer
Hi Gary, if you just wanna open specific xl file, you can directly use workbooks.open “c:\xlfilename.xls” function.
Silas
Is there an easy way to open a non-excel file, based on the contents of the cell in an excel file.
For example, if i have a file
DP1253 – 50393.tif, can I open it automatically on a macro run if i have a cell (say A1) with a value DP1253
Thanks in advance