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"
Program Code Explanation:
- Workbook_Open: Excel will execute this code every time You open this Excel Workbook.
- Msgbox: Built-in function used to display a Message in a pop-up window.
- 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.
2. Excel Macro Hello World – VBA Coding Environment
To write the above code , open a new Excel workbook & follow these steps.
- Press Alt+F11 from Excel to view VB editor.
- 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.
- Double click “Thisworkbook”.
- 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.
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”.
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.
5. Advantages of Excel Vba Macro
More interesting facts about Excel VBA Macro over other Programming Languages are:
Excel has a
- Very sophisticated database in the form of worksheets,
- Integrated with a VB editor that helps to build code in minutes and
- 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.