You are on page 1of 51

The VBA Environment

Terry Bradbury
Terry.Bradbury@Gmail.com
Overview

 Configuring for development


 The Developer tab
 Macro security
 The Macro Recorder
 The Visual Basic Editor
 The Object Browser
 The Debugger
 Developer add-ins
Configuring for Development

 Select File → Options → Customize Ribbon


 Alt + F, T, Select Customize Ribbon
 Make sure the ‘Main Tabs’ group is selected
 Select ‘Developer’ from the list of available tabs
 Click the OK button to save changes
 Tools for Access are on the Create and Database Tools tabs
 Some Office applications have no developer tools
Configuring Office 2007

 Click the Office button (orb), then the Options button


 Alt + F, I, C
 Select ‘Show Developer tab in the Ribbon’ from the Popular options
group
 Click the OK button to save changes
Help Resources

 Office 2013 uses online help


 Earlier versions of Office may not have help files installed
 From Control Panel, go to Programs and Features
 Select your version of Microsoft Office from the list
 Click the Change button above the list
 Open the Office Shared Features group
 Set VBA items to ‘Run from My Computer’
 Additional help at the Microsoft Developer Network
 Office Developer Center
 Office Developer Downloads
 Essential Downloads -> Office SDKs and References
 For Office 2013, select 2010 -> Other Versions -> 2013
The Developer Tab

 List of available tools varies between applications


Visual Basic

 The Visual Basic button opens the editor


 Use the first button on the Standard toolbar to return
 Alt + F11 toggles back and forth
 Keyboard shortcut works even without the Developer tab
Macros

 Dialog to manage macros


 Run starts the selected macro
 Step Into starts in debug mode
 Edit opens the macro code for editing
 Create adds a new macro
 No control over where this is stored
 Delete removes the selected macro
 Options allows the Shortcut Key and description to be changed
Macro Security

 Opens the Macro Security options in the Trust Center


Add-Ins

 First appeared in Microsoft Office 2010


 Same as Add-Ins group in Options dialog
 Add-Ins button accesses document Add-Ins (and Automation)
 COM Add-Ins load Component Object Model add-ins
 Only use known add-ins, and understand their purpose
Controls

 Add controls directly to the document


 Controls vary by application
 Three Types:
 Forms Controls (simpler legacy controls)
 ActiveX Controls (more complex, but more features)
 Content Controls (Word only)
 Some controls cannot be used in all contexts
 Use Design Mode to modify ActiveX controls
 Properties button depends on selected control
 View Code opens the macro associated with the control
 Run Dialog button only in Excel
Document Panel

 Document-based applications have a Document Panel button


 Provides access to the Document Information Panel
 Allows you to attach an InfoPath template
 Determines when the Document Information Panel should be shown
Macro Security

 Click the Macro Security button on the Developer tab


 Macro Settings
 Disable all macros without notification
 Disable all macros with notification
 This option should always be selected
 Disable all macros except digitally signed macros
 Enable all macros
 Use Trusted Locations instead if needed
 Developer Macro Settings
 Trust access to the VBA project object model
 Optionally enabled during development
 Always disabled during testing
The Macro Recorder

 Captures user actions and keystrokes from the user interface only
 Not all Office applications have the Macro Recorder
 Optional buttons by application:
 Word has a Pause Recording button
 Excel has a Use Relative References button
Macro Recorder Demo in Excel
Relative References
Page Setup
Macro Recorder Demo in Word
The Standard Toolbar
Arranging Windows
The Standard Toolbar (cont’d)
The Project Explorer

 Shows all documents and code modules in all open documents


 Commands are primarily on the File and Insert menus
 Can only add VBA types
 Application document objects must be added from the application
 Double-click to open code modules
 UserForms can be toggled between object and code view
 F7 for Code View
 Shift+F7 for Object View
 Context menu and Insert menu are not the same
 Insert Procedure dialog
 Project Properties dialog
The Project Explorer (cont’d)
The Project Explorer (cont’d)
The Properties Window
The Editor Window
The Editor Window (cont’d)
The Edit Toolbar
The UserForm Toolbar
The Object Browser

 Available from the standard toolbar or press F2


 Appearance controlled by the Tools -> Options -> Docking settings
The Debugger
Operating Modes

 Design Mode
 Run Mode
 Break Mode
 Break button (Ctrl+Break)
 Error in code
 Breakpoint in code
 Stop statement in code
 Watch settings
 Resume Run Mode with Continue (F5)
 Use Reset to stop
The Debugger

 The Debugger is not a single tool, but a set of tools that work together
 The Debug toolbar
 Transport controls
 Breakpoints (toggle, clear all)
 Step through code (into, over, out, run to cursor)
 Windows (immediate, locals, watch, call stack)
 Watches (add, edit, quick watch)
 The Debug object
The Immediate Window
The Locals Window
The Watch Window
The Call Stack
Compile VBAProject
Developer Add-Ins

 Designed to work with the VB IDE


 Configure startup settings using the Add-In Manager
 Featured Add-Ins
 Smart Indenter
 VBE Tools
 VBAcodePrint
 MZ-Tools
VBE Tools

 For general use


 ‘Location’ label on References dialog resized
 ‘Close All Windows’ on the Window menu
 Module size button on VBE Tools toolbar
 For UserForms development
 Allows controls to be ‘nudged’ (positioned)
 Allows controls to be sized
 Keyboard and mouse supported
 Allows controls to be renamed and automatically renames code
Smart Indenter
VBAcodePrint
MZ-Tools
Summary

 Configuring for development


 The Developer tab
 Macro Security
 The Macro Recorder
 The Visual Basic Editor
 The Object Browser
 The Debugger
 Developer Add-Ins
Add-Ins

 Office Automation (VBE Tools and Smart Indenter)


 http://www.oaltd.co.uk/
 StarPrint Tools (VBAcodePrint)
 http://www.starprinttools.com/
 MZ-Tools
 http://www.mztools.com/

You might also like