1. Your First Macro
1. Your First Macro
Stephane Ruchet
2
Steps To Your First Macro Recording
• Do a test run before recording
• Record the macro
– Macro button on the left of the status bar
– Developer tab -> Record macro
3
Visual Basic Editor
• Hierachy :
– Close VBE -> Excel file stays open
– Close Excel File -> VBE closes
• One VBE for all open Excel files
• To open VBE
– ALT + F11 (Mac: ALT + Fn + F11)
– Developer Tab -> Visual Basic
4
Layout Personal Macro Insert Procedures,
Workbook Modules and Userforms
Edition options
Go back to Excel
ALT + F11
Run & stop your code
Project view
Immediate Window :
great for code testing
5
Fine-Tune your setup (Windows)
• Excel -> Options -> Trust Center -> Trust Center Settings
• Macro Settings -> « Enable VBA macros »
• Protected View -> 3x Uncheck «Enable Protection View»
6
Windows Protection
• If you see the following message:
In File Explorer, browse to the location of your workbook, right-click the file, and
select Properties from the context menu. Check the “Unblock” box in the
Properties dialog box, then click OK.
7
Fine-Tune your setup (Mac)
• Enable all macros
8
Fine-Tune your setup (Mac)
• Open the Visual Basic Editor
• Excel -> Preferences
9
Disable Add-ins
• You do not need additional Add-ins activated for the scope
of the class. Disable them to clear the project explorer.
10
Different ways to run Macros
• Tab Developer -> Macros
• Use the assigned shortcut key (you can always assign a short key after saving)
• Add a shortcut in the Quick Access Toolbar
• Add a shortcut in the Ribbon
• Insert any shape/icon and assign the macro to it (right-click on the object)
• Insert a Form Control button
– Windows: Developer Tab -> Insert -> Form Controls
– Mac : Developer Tab -> Select relevant Form
Windows Mac
11