You are on page 1of 31

Excel Using Macros

LEVEL – Learner
Overview

This chapter talks about :


Advance excel formulae required for test reporting,
metrics, Creating a record & playback macros ,
VBA forms and
Creation of a simple quiz tool using VBA macro
Objective

After completing this chapter, you will be able to

 Work on the Advance excel formulae required for test


reporting,
 metrics, Create record & playback macros ,
 Work on VBA forms & macros and
 Create a simple quiz tool using VBA macro
Do You Know ?

Form Controls and ActiveX controls cannot be


added in an excel sheet and tagged to a
macro code
ANS: NO

Quality Center defects tab is used to implement


in Defect Management Process

ANS : YES.

4
Macros – Introduction

• Macros is essentially a piece of code that can run in


the background & interact with Excel
• Macros are written in Visual Basic – VB Language
(OOPS)
• Visual Basic language can be used to interact with
any Microsoft Office applications & Windows
– Excel
– Power Point
– Outlook
– System files & folders etc
5
Where to begin ?
3- Users can open
Macro’s windows from
2- Once enabled
here or by pressing
Developer Tab will be
ATL+F11
reflected here

3- Security Options are


displayed here

1- Developer Tab can be


enabled through
File -> Options ->
Customize Ribbon

6
Security Options
1 – Not Recommended
since Macros will not run
at all

2- Default and favored option


for users
Will get a notification on top
3 – Since not all Macros
when Excel is opened for the
are not digitally signed,
first time
this is not used typically

4 – Although not
Recommended, but can
be used to reduce hassle
View, Edit & Execute
1 – Click Macros To View
list of Macros stored in
current workbook

4 – Edit Option can be


used to View the Macro
Code

2 – List of all Macros is


displayed here

3 – Macro can be run


using by clicking Run or
assigning a shortcut
Beginners Guide to VBA

1 – Displays the
Workbook Name in
which the Macro is
written

3– Every macro begins


with “Sub (Name)” &
ends with “End Sub”

4 – Code that is written


2 – All the Macros stored between Sub & End Sub
in one any of the Excel are executed when
Objects Macro runs
Debugging

VBA code for Enter the


Value as “Cognizant” and
change the Interior and
Font Color and Size.

Output for the


Above Code will
change Cell - B3
Debugging Options
1 – F8 is used to execute Line
by Line

3 – Break points are kept at


any executable line & system
will wait for human
intervention to further
execute code

2 – Add watch option is used to monitor


Variables & Objects in the scope of
Macro for better understanding
Step by Step Execution -1

No Data in Cell B3

Key F8 can be pressed to


move each line of code
Step by Step Execution -2

Cell B3 has Value


Cognizant

Key F8 can be pressed to


move each line of code
Step by Step Execution -3

Font in Cell B3 is not


Bold

Key F8 can be pressed to


move each line of code
Step by Step Execution -4

Font in Cell B3 is
changed to Calibri

Key F8 can be pressed to


move each line of code
Step by Step Execution - 5

Background Color in
Cell B3 is changed

Key F8 can be pressed to


move each line of code
Step by Step Execution - 6

Font Color in Cell B3 is


changed

Key F8 can be pressed to


move each line of code
Record Macro

• Recording a Macro is the simplest way to


understand VB
• Users can record any action performing on
Excel through Record Macro
• Similar to existing Macros users can View, Edit
& Manage a recorded macro
Recording a Macro
1 – Users can click on Record
Macro to start Recording

2 – Name of The Macro to be


recorded

3 – Shortcut Key to execute


the Recorded Macro

3 – Place to store the Macro


( Storing in Personal Macro Workbook
will help users to retrieve & run macro
from any open workbook from the same
system )

5 – Final step to stop recording is by clicking on


Stop Recording
(This will appear only if macros is currently
being recorded)
Inbuilt Controls

• Lot of UI features are provided to end users


through From control & ActiveX Controls like
– Buttons
– Ratio Button
– Check Boxes
– Scroll bars etc.
Adding Check Box

Adding Check Box


control from
ActiveX control
and changed the
caption as “Check
Box Status”
VBA for Check Box & Output

VBA Code:
Based on Check Box
selection, output will
change

Output
Adding Option Button

Adding Option
Buttons from
ActiveX control
and changed the
caption as “Add”
and “Multiply”
VBA for Option Button & Output

VBA Code:
Based on Option button
selection, output will
change.

Output for Multiply option, if we select Multiply


option, automatically Add option will get turn off

Output for ADD


option
Adding Calendar Control

Adding Calendar
Control option
from More
Controls

25
VBA For Calendar Event

VBA Code:
If the user clicks the
calendar date,
corresponding date will
display on text box

Selected Date is
displayed on text
box
Adding Text Box

Based on our
selection from
More controls,
calendar widget
will appear

Adding Text Box


control from
ActiveX controls
VBA For Text Box

VBA Code:
If the user clicks the Text
Box, selected calendar
date will display on text
box

Selected Date is
displayed on text
box
Help

Two of the biggest Help for Macros is inbuilt within VBA


Windows
•Object Browser

•Help – F1

Lot of forums, examples & tutorials are just a click away


from your Browser 
29
Summary
• Easiest way to begin macro is to record actions & generalize
the learning

• Learning various Loops & Conditions (For, Do, If) in


programming is essential to modify any macro

• Macro enabled workbook should be stored in XLSM format


– Excel with XLS & XL SX extension will not store any VB Code

Refer the following attachment for various


Microsoft Excel
functions like Math, Vlookup, Date etc. Worksheet

Refer the following attachment for


Microsoft Excel
various charts 97-2003 Worksheet
You have successfully completed –
Excel Using Macros - Learner

You might also like