A simple Hello World program written in VBA (Visual Basic for Applications) for Microsoft Excel.
HelloWorld.bas- VBA module containing three Hello World examples
Displays a message box with "Hello World!" message.
Writes "Hello World!" to cell A1 with bold formatting and increased font size.
Prints "Hello World!" to the VBA Immediate Window (useful for debugging).
- Open Microsoft Excel
- Press
Alt + F11to open the VBA Editor - Go to
File>Import File... - Select
HelloWorld.bas - Press
F5or go toRun>Run Sub/UserFormto execute the macro
- Open Microsoft Excel
- Press
Alt + F11to open the VBA Editor - Go to
Insert>Module - Copy the code from
HelloWorld.basand paste it into the module - Press
F5to run the macro
- After importing/adding the code, return to Excel
- Press
Alt + F8to open the Macro dialog - Select
HelloWorld(or any other macro) - Click
Run
- Microsoft Excel (any version that supports VBA)
- Macros must be enabled in Excel
To enable macros in Excel:
- Go to
File>Options>Trust Center>Trust Center Settings - Click on
Macro Settings - Select
Enable all macros(orDisable all macros with notification)
This is a simple educational example and is free to use.