150 likes | 167 Views
Learn how to create, modify, and run macros in Excel to automate processes effectively. Discover how to create toolbars and menus for easy macro access, and run macros automatically when opening a workbook.
E N D
CA202Spreadsheet Application Automating Repetitive Tasks with Macros Lecture # 12 Dammam Community College
Objectives In this chapter you will learn to: ✔ Open and run macros. ✔ Create and modify macros. ✔ Create toolbars and menus to hold macros. ✔ Run a macro when a workbook is opened.
Introducing Macros • Some sequences involve many steps and take time to accomplish by hand. • Rather than doing by hand every time, you can create a macro, to do repeated things. • Alt+F8 to bring Macro dialog box or click Tools Macro Macros…
Introducing Macros • If you have trouble running macros, you can click Tools Macro Security… • Click on Medium option button and click OK
To See How Macro Works • To see how the macro works, you can open the Macro dialog box, click the name of the macro you want to examine, and then click Step Into.
To See How Macro Works • To execute an instruction, you press F8. The highlight moves to the next instruction, and your worksheet changes to reflect the action ExerciseMacrosView
Creating and Modifying Macros • Once you have planned your process, you can create a macro by Clicking: • Tools Macro Record New Macro. • Type the name of macro • click OK. • The Stop Recording toolbar appears. ExerciseRecordMacros
Creating a Toolbar to Hold Macros • Run a macro from toolbar makes your worksheets much easier to use, especially for people with less experience. • To create a toolbar Click Tools Customize.
Creating a Toolbar to Hold Macros • Once you have created the new toolbar, you can assign your macros to it. • Click Commands tab • Two items will appear in the Commands list: • Custom Menu Item. • Custom Button. • To add a button to your new toolbar, drag the Custom Button item to the toolbar.
Creating a Toolbar to Hold Macros • Right Click on toolbar and assign the Macro
Creating a Toolbar to Hold Macros • To Delete a toolbar click Tool Customize • Click on Toolbar tab • Select the Toolbar • Click on Delete • Click OK to confirm deletion
Creating a Toolbar to Hold Macros • You can change the image. • Right Click on Image • Select Change Image Button
Creating a Menu to Hold Macros • Click Tool Customize • Click Command New Menu • Drag New Menu to desired spot • Right click and change the Name of menu ExerciseCustomMenu
Running a Macro When a Workbook Is Opened • You can run your macro by hand, or from a toolbar button, or a menu. • You can run a macro automatically even when you are opening a work book. • Whenever Excel finds a macro with a name starting with Auto_ (Auto followed by an underscore), it runs the macro when the workbook to which it is attached is opened. ExerciseRunOnOpen
Chapter 12 Key Points • Macros are handy tools you can use to perform repetitive tasks quickly, such as inserting blocks of text. • You don’t have to be a programmer to use macros; you can record your actions and have Excel save them as a macro. • Always keep control over whether you want to enable macros in a particular workbook by setting your security level to Medium or High. • If you’re curious about what a macro looks like, you can display it in the Visual Basic Editor. If you know a little VBA, or if you just want to experiment, feel free to modify the macro code and see what happens. • You can create toolbar buttons or menu items that, when clicked, will run a macro. • Starting a macro name with Auto_ tells Excel to run the macro when it opens the workbook to which the macro is attached.