Professional Documents
Culture Documents
For Presentation On April 14, 2005 At The Monthly Meeting Of The Morris (County, NJ) Micro Computer Club (M2C2) http://morrismicro.home.att.net/ And On June 2, 2005 At The Monthly Meeting Of The Computer Club of the ExxonMobil Annuitant (and Retirees) of the Morris (County, NJ) Area (EACMA) And On November 18, 2005 At The Monthly Windows Pains Meeting Of The Amateur Computer Group Of New Jersey (ACGNJ) http://www.acgnj.us/ To download your own copy of some of the handouts used in this presentation go to http://excelvbaprogramming.homestead.com/ and click on Free Courses. 1
Understanding the above joke is NOT a prerequisite for this presentation. The only pre-requisite for this talk is a basic working knowledge of Excel and Word (Versions 1997 or newer).
2
Agenda
Demonstrations. What is a macro? Security settings to allow macros to run. How to record (and save) a macro. How to run your saved macro. How to edit a saved macro. Special macros:
auto_open auto_close etc.
MS/Word Toggle strikethrough (toggle between on and off) Control Shift S Color highlighted text (toggle through various colors) Control Shift R Change the spacing between paragraphs Several toolbar buttons Insert symbol (e.g., bullet, degree sign, legal, etc.) CSB, CSW, CSN, etc. Toggle superscripts and subscripts Cntrl Shft Y Preserve destination format during paste Control V Delete to end of line Cntrl Shft Delete Toggle the (in)visibility of hidden text (Control + H) Cntrl Shft I Keep lines together (or not) (toggle) Cntrl Shift K Return to last cursor position when opening a saved document Write a check MS/Excel Toggle strikethrough (for the selected cell) Control Shift S Toggle colors (cycle through red, blue and black) Control Shift R Wrap text and adjust row height to fit Calendar control Meeting attendance records and sign-in sheets Show page breaks Show page breaks automatically (AutoOpen) Not working? Record the time of day that a document is opened (AutoOpen) Launch a favorite file (from a customized Work dropdown menu) Animated X-Y graphs (e.g., plots of y=mx+b, Lissajous patterns, etc.) Filter and sort a financial data base or check book log Financial planning (lifespan of an annuity) Build a control chart Blue text: Simple / educational 4 Download stock prices Red text: Fun / interesting Solve a checkerboard puzzle
Demonstrations
Games
PSNs Blockade game
Malicious macros
Delete or move files, send emails, dial the phone, etc.
Anything you can do with your keyboard and mouse can be done with a macro, automatically.
5
What Is A Macro?
A macro is a set of computer instructions
(a mini-computer program), activated by an event, that tells the computer what to do. Macros are often written (or coded) in a computer programming language called Visual Basic For Applications (VBA), a specialized subset of Visual Basic (VB). A macro can be a simple single instruction (like coloring selected text red) or, it can be several thousand lines of complicated code (like building a stock price chart)
Caution:
The undo command does not always work with macros. (Before you run a macro be sure that you really want to.)
7
Launch Excel, Word, or any other MS/Office application. Click - - - Tools | Macro | Record New Macro. Select a place to store it:
Global: - - - Available to all documents, or Local: - - - - Restricted to the current document.
Option: May assign a shortcut key (Control + __ ). Click OK to begin recording keystrokes. IMPORTANT: When done recording, remember to click STOP RECORDING.
8
Special Macros
(Triggered By Special Events)
Word
AutoExec Runs automatically when you start Word AutoNew Runs automatically when you create a new document AutoOpen Runs automatically when you open an existing document
(E. g., An AutoOpen Macro can be used to set the cursor at last edit point.)
AutoClose Runs automatically when you close a document AutoExit Runs automatically when you quit Word
Excel
AutoLoad Runs automatically when an Excel workbook is opened) RunAutoMacros
RunAutoMacros xlAutoOpen RunAutoMacros xlAutoClose RunAutoMacros xlAutoActivate RunAutoMacros xlAutoDeactivate
These special macros are included in new versions of VBA for backward compatibility with older versions that use Auto_Open, Auto_Close, etc. For new Visual Basic code, you should use the Open, Close, Activate, and Deactivate events instead of these macros.
11
Conclusion
You can use macros to automate routine tasks in Excel, Word, or any other Microsoft Office application. The easiest way to create a macro is to record keystrokes and then edit (fine tune) the recording. The easiest ways to run a macro are to:
Assign it to a new button on your toolbar, or Assign it to a fast path on your keyboard, or Click - - - Tools | Macro | Macros
If you can do it with a keyboard and mouse, then you can automate it with a macro.
12
Other Microsoft OFFICE webcasts (including more Tips And Tricks webcasts)
http://www.microsoft.com/seminar/events/series/connectedproductivity.mspx
Example: msnews.microsoft.com/microsoft.public.excel.programming
http://msdn.microsoft.com/
Microsoft Developers Network (MSDN) (for developers and more advanced users) Microsoft Online Training (webcasts, videos, other free online training)
http://office.microsoft.com/training Enter training and macro in the 2 search boxes at top of window and click go. Includes a course about writing your first Excel macro.
May 24, 2005 Issue Of PC Magazine Article on Pg 60 entitled Demystifying Excel Macros
http://www.pcmag.com/
Amateur Computer Group Of New Jersey (ACGNJ) VBA Special Interest Group (SIG)
Meets in Scotch Plains, NJ - http://www.acgnj.org/ or http://s90950543.onlinehome.us/acgnj/groups/vbasig.html
13