VBA code to open a workbook
Opening a Workbook 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 MyBook.xls located in the folder named MyWorkBooks on drive D.
Sub OpenUp()
Workbooks.Open("D:\MyWorkBooks\MyBook.xls")
End Sub
|