Skip to main content

2. Excel VBA: Creating our first macro

  1. Open the Visual Basic editor. Go to the developers tab. Click on Visual Basic. A new window will open.
    Opening visual basic editor
  2. Go to the top menu and select Insert –> Module.
    Visual basic editor windows
  3. On the left of your screen you can see that a new window is created.
    A new module is created
  4. Enlarge the window so we can start making our first macro. We will name our macro “HellowProgram”. msgBox will create a message box with the text “Have a nice day”. “End sub” indicates¬† the end of our program. Close the window.

    Our first macro

  5. Now we will link the macro to a button. So it will be activated when we click on it. Your cursor will turn into a cross. By holding the alt key you can make sure that excel uses the existing grid lines. You can select multiple cells if you want.
    inser button to excel workbook
  6. Select the name of the macro we’ve just made. I named my macro ” HelloProgram” . Click on “Ok”.

    assign macro in excel

  7. Now you can use the button in your workbook. But first we want to edit the text. Edit the text of the button by right clicking on it. And clicking “Edit Text”.
    edit text of button
  8. Edit the text. You can name it any way you like.
  9. Click on the button. the “Have a nice day” message box will appear. Our first macro works!
    pop up message 2
  10. ¬†Click on “Ok” to close the window.

 

 

Leave a Reply

%d bloggers like this: