Microsoft Office Tutorials and References
In Depth Information
An Introductory Example
An Introductory Example
To get the ball rolling, I begin with a simple example of a VBA procedure. This
procedure, named CountCharts , displays a message box that tells you the name of the
active sheet and the number of charts on the sheet. Figure 14-1 shows the message
box that pops up when this macro is executed.
Figure 14-1: This message box displays the sheet name and the number of charts.
To create this procedure, insert a VBA module into a project and then enter the
following VBA code into the code window of the module:
Sub CountCharts()
‘Counts the charts on the active sheet
Dim Msg As String
Msg = ActiveSheet.Name
Msg = Msg & vbNewLine
Msg = Msg & ActiveSheet.ChartObjects.Count
MsgBox Msg
End Sub
To execute the macro, activate a worksheet and press Alt+F8 to display the
Macro dialog box. Select CountCharts from the list and click Run. Or, you can
execute directly from the VB Editor. Put the mouse cursor anywhere within the
procedure and then press F5.
Look closely at the code line by line:
Search JabSto ::

Custom Search