Get easy step by step guide to code a Excel Vba hello world program.

It is perfect place to start Excel Programming for beginners.

1. Excel VBA “Hello World” Macro Program

VBA “Hello World” program is so easy just like teaching a kid – ‘A for Apple’.

Lets see how does the actual code looks like:

Private Sub Workbook_Open()
    MsgBox "Excel VBA Hello World Program"
End Sub

Program Code Explanation:

  1. Workbook_Open: Excel will execute this code every time You open this Excel Workbook.
  2. Msgbox: Built-in function used to display a Message in a pop-up window.
  3. End sub: Marks the end of the sub procedure.

It is so easy. Isn’t it.

Lets see where to write this code in Excel & how to execute.

Read Also: How to Write Google App Scripts – Hello World Google App Script?

2. Excel Macro Hello World – VBA Coding Environment

To write the above code , open a new Excel workbook & follow these steps.

  1. Press Alt+F11 from Excel to view VB editor.
  2. Info Only: On the left hand side panel, there will be options for Sheet1, Sheet2, Sheet3 & Thisworkbook.
    • Inside Thisworkbook – you can write Macro code common for the whole workbook.
    • Inside Sheet1 – You can write code specific to Sheet1.
    • Sheet2 & Sheet3 – same as above step.
  3. Double click “Thisworkbook”.
  4. Copy & Paste above code to empty right side coding area.

We have complete the coding part.

Note: Microsoft Office Excel should have installed with VBA option enabled during MS Office Installation. If the below steps did not work, re-install MS Office.

Also Read: How to Refer Workbooks & Worksheets in Excel Through VBA?

3. How to Execute the Hello World VBA Code

Press F5 to execute the code.

A message box will appear displaying “Hello World VBA Program”.

Apart from pressing F5, we can run a program using a Command button (or any GUI like button), hyperlink URL, Time triggered Macro etc.,

4. Save File with XLSM (Macro Enabled Workbook)

Now the important step. Store all the precious work you have learned. Save the workbook with “Macro Enabled Workbook” (XLSM). Close the workbook and open it with macros enabled. The Hello world message box will appear every time the document is opened.

End of “Hello World” Excel VBA Macro Programing. Now you are familiar with this VBA Alien, what to do next – Get ready to Roam in Space. But be ready to equip with special tips in upcoming posts.

More Tips: Add a Command Button in Excel Sheet and Assign a Macro

5. Advantages of Excel Vba Macro

More interesting facts about Excel VBA Macro over other Programming Languages are:

Excel has a

  1. Very sophisticated database in the form of worksheets,
  2. Integrated with a VB editor that helps to build code in minutes and
  3. Execute the code without worrying about Compilation,  Build or Linking to EXE etc.,

These points make Excel macro more sophisticated & a major reason for its long term popularity.

Though there is a very big debate on whether Excel Macro is dead, I am still making a living with VBA coding knowledge.

Leave a Reply