Searching...
Wednesday, May 8, 2013

Excel Macros - Hello World

Macros is one of many things which makes an application great. MS Excel also contains this feature. If you have a repetitive task on Excel, you can then automate those steps using Excel Macros. On top of that, if you have first hand knowledge of Visual Basic, the possibilities of what you can do with Excel are infinite.

In this section we will learn a, how to enable a developer tab on MS Excel 2010. You will also learn to write a your first Macro. Open a new workbook and click on "File" on Excel ribbon


Next click on "Options"




A pop-up window will appear. Click on "Customize Ribbon"



Check the "Developer" check-box on the list and click "OK"



After clicking "OK", you will notice that a new tab named "Developer" has appeared on the main workbook



Click on this tab, and choose "View Code" option on it.



A new window will be opened. This is the "Visual Basic" editor which can be used to write VB code to do functions on Excel workbook.



Type the following on this editor, and close it.

Sub HelloWorld()

    MsgBox ("Hello World")
    
End Sub

The first line is a declaration of a Macro. This will also be your Macro name. In the second line, you have specified that, whenever this Macro is invoked, show a message box with "Hello World" message. The Third line indicated, end of macro.






Go to the main workbook and click on "Macros" on "Developer" tab



A pop-up will appear, click on "Run"




You will see a message box as follows.




Congratulations !! You have developed your first macro.






0 comments:

Post a Comment

 
Back to top!