Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Excel 2007 © Wiley Publishing. 2007. All Rights Reserved. The L Line The Express Line to Learning L Line.

Similar presentations


Presentation on theme: "Microsoft Excel 2007 © Wiley Publishing. 2007. All Rights Reserved. The L Line The Express Line to Learning L Line."— Presentation transcript:

1 Microsoft Excel 2007 © Wiley Publishing. 2007. All Rights Reserved. The L Line The Express Line to Learning L Line

2 Programming Excel: An Introduction to VBA and Macros 15 Running your first macro Creating your own macro Activating and using the Developer tab Debugging macros in the Visual Basic Editor Adapting a macro Adding a macro to the QAT Looking at other uses for macros Understanding trusted locations and trusted sources Stations Along the Way

3 Why Use Macros? Macros enable you to automate a process you perform in Excel: A series of steps you perform regularly A complicated process you need to be able to repeat exactly each time They make it easier to do your work Record your keystrokes and then use VBA to fine-tune macros (or create them from scratch)

4 Sample Macro Code This macro code performs a progression First line defines name; lines that begin with quotation marks are comments; the macro follows Sub progression1() ' ' This macro takes two numbers from consecutive cells in ' column C and finds the next 10 numbers in the progressive ' series ' For I = 3 To 13 nextvalue = "c" & I Range(nextvalue).Select ActiveCell.FormulaR1C1 = "=R[-2]C+R[-1]C" Next I End Sub

5 Creating a Macro Easiest method is to record the macro; Excel watches what you do and remembers the steps Access the Record Macro command from the View tab (Macros button) Name the macro, assign shortcut key, and specify location and description Record the macro and then stop recording when macro steps complete

6 Tips for Creating Macros Practice what you want the macro to accomplish; jot down steps beforehand Give macros a descriptive name Use an unassigned shortcut key Step through the macro to debug it Edit macro code or re-record macro Save macro file in.xlsm format

7 Using the Developer Tab More options for working with macros Developer tab doesn’t display by default; you must activate it Select “Show Developer Tab in the Ribbon” in the Excel Options window (Popular options) Developer tab displays in the Ribbon with four groups: Code, Controls, XML, and Modify

8 Viewing Code in the Visual Basic Window Open file containing macros and choose Visual Basic on Developer tab Visual Basic window has four areas: Command menus across the top Top-left window shows project elements Bottom-left window shows properties Large window on right shows VBA code Double-click a module to see code

9 Debugging Macros Most code includes errors to debug: Syntax – typos and command errors Logic – Excel doesn’t understand coding Scope – code works, but not optimally Run macro with error; Visual Basic Editor opens and highlights error Note type of error in message box Use Debug button and Help info Fix coding and rerun until error-free

10 Adapting a Macro Control what a macro does by: Asking for user input to determine path Basing macro path on a condition Placing processing in a repeating loop that controls the code Add helpful comments for users: Describe in detail what the macro does Explain limits, conditions, variable names

11 Adding a Macro to the QAT Add a button to the QAT to quickly access your macro Click Customize in the Excel Options window and choose Macros category Specify current file or all files Select macro name and add to QAT Click Modify to add custom icon Click button in QAT to run the macro

12 Other Uses for Macros Creating complex charts Performing complicated computations Applying detailed worksheet formatting Simplifying data entry Opening and cleaning text and CSV files Writing VBA applications that run on top of Excel

13 Trusted Locations and Trusted Sources Trusted locations contain code that is trusted from any source Includes default template locations, user startup folders, Excel add-ins location Use Trust Center to add trusted locations Trusted sources include trusted publishers and companies who develop coding and use certificates to verify their identity

14 Discussion Questions Why do you need to enable macros? Which format should you use when saving Excel files with macros in them? Why would you use the Developer tab? Why would you want a macro to contain an If...Then statement? Why would you want a macro to contain a loop?

15 Discussion Questions (cont.) Where do you debug macros? What is the difference between a syntax error and a scope error? Why should you trap errors? How do you add a macro to the QAT (Quick Access Toolbar)? What is a trusted source?


Download ppt "Microsoft Excel 2007 © Wiley Publishing. 2007. All Rights Reserved. The L Line The Express Line to Learning L Line."

Similar presentations


Ads by Google