Skip to main content

Viewing macro code

You can use either of the following methods to view the macro code:

On Excel’s Developer tab, click the Visual Basic button in the Code group (or Press Alt+F11 shortcut key).

In the Visual Basic Editor, select View > Project Explorer – to open the “Project Explorer” window. Alternatively, you can use the keyboard shortcut Ctrl+R.

In Project Explorer, click the + button beside the Book1 project to expand its contents.

In “Modules” folder, double-click the Module1 node.

The macro should look something like this

Sub Helloworld()
'
' Helloworld Macro
' This is my first macro
'
' Keyboard Shortcut: Ctrl+j
'
    Selection.FormulaR1C1 = "Hello World"
    Selection.Font.Bold = True
    Selection.Font.Italic = True
    Selection.Font.Underline = xlUnderlineStyleSingle
End Sub

The line 1: The recorded macro is a Sub procedure named Helloworld.

Lines 2 to 7 are comments. Notice that Excel inserts some comments at the top of the procedure. These comments are some of the information that appears in the Record Macro dialog box. These comment lines (starting with an apostrophe) are not really needed, and removing them has no effect on how the macro runs.

The line 8: This statement causes the text you typed while recording to be inserted into the selected cell.

The line 9: format font to bold.

The line 10: format font to italic.

The line 11: format font to underline.

The line 12: This indicates the end of the macro.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>