You are on page 1of 11

CREATING MACROS

TO AUTOMATE ROUTINE TASKS IN


EXCEL (advanced)

Juniors 2020
Computer Science

1
Topics Included:
• 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.
• Help and additional resources.
2
Other Uses Of Macros
• MS/Outlook,yahoo or gmail (eMail)
– Abort SEND if email SUBJECT line is empty.
– Customize your auto-signature with time, date, etc.
– Auto-reply to spam to remove from mailing list
• 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.

3
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)
– A macro can also involve decisions and branches
• For example: If selected text is blue,
Then color it red;
Else, color it blue.
4
Security Settings To Allow Macros
• Launch Excel, Word, or other Microsoft Office application.
• Click - - - Tools | Macro | Security.
• Set your security level to medium.
– Affects all Microsoft Office applications (Word, Excel, etc.)
– Might need to restart the application before setting takes effect.
• You can digitally sign your macros.
– You, and other people who might use your macros can change their
security setting to recognize your signature and allow macros signed
by you to run without further prompting.

• Caution:
– The “undo” command does not always work with macros.
(Before you run a macro be sure that you really want to.)
5
How To Record A Macro
(i.e., How To Record Keystrokes)

• Launch Excel, Word, or any other MS/Office


application.
• Click - - - Tools | Macro | Record New
Macro.(depending on your Excel version).
• 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
6
click ”STOP RECORDING”.
Running A Saved Macro
• There are many ways to run / launch a saved macro.
• Here are just a few:
– Select - - - Tools | Macro | Macros (depending on your Excel
version)…
– Use shortcut key(s) - - - (Control + __ or Control + Shift + __ ).
– Create a button (or other control) for it on your document.
– Program it to be auto-activated by an event or timer.
– Create a new button in one of your toolbars.
– Create a menu item for it on an existing, or new,
drop-down menu.
– Add it to a right-click menu (a context-sensitive menu) triggered
by a right-click event.
– Tie it to another event such as
• Moving the cursor
• Selecting a different cell (in Excel)
• Opening a file 7
• Having no activity for a specified time period
Editing A Saved Macro
• Launch Excel, Word, or any other Office
application.
• Open the document containing the macro
that you want to edit.
• Click - - - Tools | Macro | Macros …
• Select the macro that you want to edit.
• Click Edit.

8
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.
9
Answer the following questions
1)Define the term MACRO.
2)What is a malicious macro?
3)Describe the acronym VBA.
4)Why do you think you need to change the
security settings while working with macros?
5)Write the steps to record a new Macro in
Excel.
6)Name 3 ways to run a saved macro.
7)In your own word ,what does the term
10
automate refers to?
EMAIL
Send me the answers of these questions in
a Microsoft Word document.Attach the file
and send it back to the following email
addresses:
raf_eflores@yahoo.com or at
espptx2017@gmail.com
Thanks.Mr Flores

11

You might also like