none
Call A Visual Basic Macro On Startup Of Spreadsheet RRS feed

  • Question

  • Hi

    I have an Excel vba macro to have an input to certain cells. However I lack the knowledge to make it run when the spread sheet starts and also call it when a button is pressed

    Thank you in anticipation of your responses

    Emersont1

    Wednesday, February 26, 2014 9:50 AM

All replies

  • Lett's say that your macro is named MyMacro.

    1) Press Alt+F11 to activate the Visual Basic Editor from Excel.

    Double-click ThisWorkbook under Excel Objects in the project explorer on the left hand side.

    Copy the following code into the ThisWorkbook module:

    Private Sub Workbook_Open()
        Call MyMacro
    End Sub

    Press Alt+F11 to return to Excel.

    2) Activate the Developer tab of the ribbon.

    Click the Insert button in the Controls group.

    Click on Command Button under Form Controls.

    Either drag a rectangle on the worksheet or click on the worksheet.

    Excel will display the Assign Macro dialog.

    Select MyMacro, then click OK.

    Click outside the button.

    (If you need to move or edit the button later on, right-click it)


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Wednesday, February 26, 2014 2:53 PM