This tutorial shows you how to create a hello world macro in Excel.
For the purpose of this lesson, we go through the steps on a PC running the Windows operating system. In addition, these steps should work perfectly in Excel 2007 or higher.
A macro is a set of commands or actions that make it easier for you to perform tasks you plan use often.
Steps to create a macro to show hello world
Follow the steps below to create a macro to display hello world in Excel.
Steps 1 and 2
- In a new or existing sheet, click on a cell. Currently, we are in cell A1. Click on Developer from the toolbar. The Developer ribbon appears.
Note: If you do not see the Developer command on the toolbar, then follow this quick tip to show it. - Under the Code group, click Record Macro. The Record Macro dialog box appears.
Although it is not necessary, you should give your macro a unique name. Preferably, more than three characters in length.
Steps 3 and 4
- In the Record Macro dialog box, enter a name for your macro in the Macro name input box.
Note: You should use underscores indicate spaces. Also, we like lowercase or CamelCase. However, you can use any case you like. - Click OK. The recording process starts.
Now, there are two things you may notice.
Firstly, under the Developer ribbon, the Record Macro option changes to Stop Recording.
Secondly, the status bar, at the bottom-left of Excel displays a square icon.
In both cases, you click on these commands to stop recording your macro.
Steps 5 and 6
- So, we use cell D1 to type “Hello, world!” However, you can type it in any cell.
- After you finish typing, press Enter and click Stop Recording from the Developer ribbon. At last, you have just created a macro.
Now that you have your macro set, let us see if it works.
Test your macro
Before we test our macro, clear the sheet. It helps to have a clean sheet for this test. A quick way to clear the sheet is by pressing Ctrl + A, and pressing Delete.
Steps to test your macro
Follow the steps below to test your macro.
Steps 1 and 2
- Click on any cell on the sheet.
- From the Developer ribbon, click the View Macros option, under the Code group. This will open the Macro dialog box.
Steps 3 and 4
- From the Macro name list, select the macro you just created.
- Click Run. Finally, you should see your “hello world” text in the cell you selected.
Save your hello world macro
From the toolbar, select File…Save As. This will open the Save As screen.
- Under the Save As screen, give your document a name. In our case, name our document hello_world.
Then, select Excel Macro-Enabled Workbook (*.xlsm) from the dropdown options, below your filename. This file type will allow you to run your macros in Excel. - Lastly, click Save.
Now, you can use this macro anytime you choose.
Success!
So, were you successful? Congratulations, you did it!
If you had any issues, then give it another shot.