Opening a Workbook Using VBA in Excel
The Excel training video takes you through all the steps involved in writing and executing the macro.
- Click on the Tools menu in the menu bar, select Macro and then Visual Basic
- In the Visual Basic Editor click on insert in the menu bar and select Module
- The first green line with an apostrophe at the beginning denotes a remark and let’s the user know about the utility of the following macro
- Define a macro name like OpenUp()
- Then complete the code as shown below
- Here we use the Open method from the workbooks collection. If you remember last time we used the Add method to create a new workbook.
- You’ll notice that you need to define the complete path to the file to be opened
- The following procedure in Excel opens a workbook named create-new-work-using-macro.xls located in the sub-folder named My Documents on drive C.
Workbooks.Open(“C:\Documents and Settings\Dinu\My Documents\create-new-work-using-macro.xls”)
We have also shown how to auto-run the ‘OpenUp’ macro.
Open Method [Excel 2003 VBA Language Reference]