MS Excel - Macros
EL AbquinaTech Ops PHwww.techopsph.com
This is not a programming class (but
we will teach a bit of code)
INTRODUCTION
If you want to eliminate repetitious command sequence or data manipulation tasks, MACROS will help as it is the automation capability of MS Excel.
A single instruction that expands automatically into a set of instructions.In computer science; it is described as a RULE or PATTERN
MACROS
Be familiar with features like:
• Create Macros by Recording• Expand macros for multiple tasks• Making macros available to all workbooks• Launch Macros by Keystroke or Toolbar• Learn VBA environment and edit code• Debug and Testing via Step-mode or split
screens• Do Loops and If commands
GETTING STARTED
• Let us know when it is appropriate to use macros
• Prepare our exercise files
Let us make sure you have MACROS in your
computer
The idea of MACROS
• Any sequences of actions can be turned into a MACRO.
• Record and Store that, so can be used in the future by doing a single click or action
• WHy Macros?
• To automate your work, and save you precious time!
Macro Example
• Open Exercises
Before starting…Security Concerns
• Security issues about macro usage;– File extension is .xlsx– Macro enabled files are .xlsm
• File > Options > Trust Center > Trust Center Settings…
• Go To Trusted Locations
RECORDING A MACRO
Option1: In the status bar (beside “Ready”).– Right click and check Macro Recording
Option2: Under VIEW Tab, there is a MACROS button, then Record Macro…
RECORDING A MACRO
• Choose A Macro Name• Make a Short-Cut Key• Store Macro in– This Workbook– New Workbook– PERSONAL Workbook
• Description
RECORDING A MACRO - Watchout
• Almost ANYTHING you do can be recording (even scrolling, clicking cells,) except for CANCEL, etc./
• After testing/running a macro, we cannot UNDO the actions– Stay away from DELETE data
RECORDING A MACRO - VBA• When you create a MACRO, you create a “small program”• Under Macros > View Macros– The small program in the language called VBA or VISUAL
BASIC for APPLICATIONS
• The more you do recording, you will get to learn about
• Later we will learn about simple codes, Function and Module
RUNNING A MACRO
• Here we will discuss how to Execute, Play Back, etc.
• There are 3 ways to run a Macro– Keystroke– Toolbar– Object
MACROS Tool
• Under VIEW Tab > Macros
KEYSTROKE
KEYSTROKE
PLAYBACK RIBBON
• You can add a button in the QUICK ACCESS TOOLBAR (Excel 2007/2010)
PERSONAL MACRO WORKBOOK
• This is a repository of MACROS you create that can be ran on ALL WORKBOOS that you might open.
USING VBA
• Visual Basic For Applications– Read code: Select Macro then EDIT– Press F11
USING VBA - Components
RECORDING A MACRO IN STAGES
• Knowing the stages of recording will make you familiar if you should need to do any change.
TIP
• Whenever you record, always look for the code by pressing F11
• This will get you familiar on how you make some alterations
2ND SESSION
CREATING NON RECORDED VBA CODE
• ABSOLUTE and RELATIVE• FOR LOOP• DO LOOP• INTERACTIVE
ABSOLUTE and RELATIVE
• Macros are recorded that relative to the initial selected cell in the worksheet
The concept of repetition is within
macros.
FOR LOOP• The concept of repetition is
enabled using macros.
DO LOOP• DO WHILE or DO UNTIL
INTERACTIVE
• A macro that pauses and asks for input from the user
Macro Project – Converting a Mailing List into a Database List
• Scoping• Partial• Testing – Press F8• Together• Joining• Stream-lining
PERSONAL MACRO WORKBOOK – ADVANCED
Conclusion
Assignment
Thank You