Tuesday, December 11, 2012

Run some VBA code when excel opens

This is a very simple post describes how to run some code when excel opens.

Excel always runs a subroutine named Auto_Open() when excel opens. Simple we can use this subroutine to do the job.

Go to developer tab then click visual basic button. If you cannot locate developer tool then you can enable developer tab by looking into the image below-

After enabling go to developer tab and then click on visual basic button. This will open visual basic editor.

Paste the following code and save the excel file. Close the file and open again. You can see the alert message as soon as the file opens-
Sub Auto_Open()
    MsgBox "The file is open now"
End Sub
Download the sample excel 2010 file here.

No comments:

Post a Comment