How to Open an Excel File from a Macro

Microsoft Excel allows a user to create macros to assist in performing frequent task automatically. A macro can be written in few easy steps and in this tutorial we will follow those easy steps to create a macro for excel.

Step # 1 – Enable developer

To create macro for excel, we need to navigate to the developer tab in the ribbon bar.

By default this tab is not visible to most users. It can be turned on by navigating to the file tab, then clicking the options button.

This will open up a new popup window. There we must select the customize ribbon option. Lastly we need to tick the developer check box listed on the right column of the window. Close the popup window and the developer tab is now visible.

Customizing ribbon

Step # 2 – Create macro

Now we must navigate to the” developer” tab located on the main menu bar

From developer tab, click the macros button which would be found under the Home Tab of menu bar.

After that a new window will pop up .Let’s name our macro “openfile” and select create. The macro now needs to be defined, and for that Excel has opened a Visual Basic editor.

We will use the () function to open the Excel file. The function requires a path to the file in order to locate and open it.

So here in our case the path is C:Users\Word\Documents\Sheet2.xlsx, so the command would be: (“C:\Users\Work\Documents\Sheet2.xlsx”)

Macro code

And that is how we can open Excel file from macro.