0% found this document useful (0 votes)
18 views

Unit -2 Excel Macro

Uploaded by

mohansai3656
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Unit -2 Excel Macro

Uploaded by

mohansai3656
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Excel - Macro

25-08-2023 Institute of Public Enterprise 1


Macro
• An Excel macro is an action or a set of actions that you can record, give a
name, save and run as many times as you want and whenever you want.
Macros help you to save time on repetitive tasks involved in data
manipulation and data reports that are required to be done frequently.
• An Excel macro is an action or a set of actions that you can record, give a
name, save and run as many times as you want and whenever you want.
When you create a macro, you are recording your mouse clicks and
keystrokes. When you run a saved macro, the recorded mouse clicks and
keystrokes will be executed in the same sequence as they are recorded.
• Macros help you to save time on repetitive tasks involved in data
manipulation and data reports that are required to be done frequently.

25-08-2023 Institute of Public Enterprise 2


What is Macro and VBA?
• A Macro is a Piece of Code
• Macros are written in Programming Language i.e VBA
• VBA is Visual Basic for Application (Excel, Word, Powerpoint etc.)
• VBA is a editor in Excel, Word

25-08-2023 Institute of Public Enterprise 3


Difference between VBA, VB and Vbs
difference
• VB is stand alone program that runs independently
• VBA is part of Excel Program and cannot work alone
• Vbs is variant of visual Basic Language used for Internet Applications

25-08-2023 Institute of Public Enterprise 4


Why Macro is required?
• Repetitive Task
• Develop new formale
• Complex task

25-08-2023 Institute of Public Enterprise 5


Synonyms for Macros
• Subroutine
• Procedure
• Program

25-08-2023 Institute of Public Enterprise 6


About Macros
• Macros is Object Oriented Program
• In Excel, anything and everything is object
• Ex: Workbooks, Sheets, cells, charts, etc.,

25-08-2023 Institute of Public Enterprise 7


Object Model for Excel
Application

Workbook

Worksheet

Range Charts Controls Sheets

25-08-2023 Institute of Public Enterprise 8


Basic Program Syntax & Program
• Sub <macro_name()>

• msgbox “Hello World”

• MsgBox 100

• End sub

25-08-2023 Institute of Public Enterprise 9


Macro and VBA
• You can record and run macros with either Excel commands or from Excel
VBA.
• VBA stands for Visual Basic for Applications and is a simple programming
language that is available through Excel Visual Basic Editor (VBE), which is
available from the DEVELOPER tab on the Ribbon. When you record a
macro, Excel generates VBA code. If you just want to record a macro and
run it, there is no need to learn Excel VBA. However, if you want to modify a
macro, then you can do it only by modifying the VBA code in the Excel VBA
editor.
• You will learn how to record a simple macro and run it with Excel commands
in the chapter - Creating a Simple Macro. You will learn more about macros
and about creating and / or modifying macros from Excel VBA editor in the
later chapters.
25-08-2023 Institute of Public Enterprise 10
Personal Macro Workbook
• A macro can be saved in the same workbook from where you
recorded it. In that case, you can run the macro from that
workbook only and hence you should keep it open. Excel gives
you an alternative way to store all your macros. It is the
personal macro workbook, where you can save your macros,
which enables you to run those macros from any workbook.
• You will learn about Personal Macro Workbook in the chapter -
Saving all your Macros in a Single Workbook.

25-08-2023 Institute of Public Enterprise 11


Macro Security
• Macros will be stored as VBA code in Excel. As with the case of
any other code, macro code is also susceptible to malicious
code that can run when you open a workbook. This is a threat
to your computer. Microsoft provided with the Macro Security
facility that helps you in protecting your computer from such
macro viruses.
• You will learn more about this in the chapter - Macro Security.

25-08-2023 Institute of Public Enterprise 12


Absolute References and Relative
References
• While recording a macro, you can use either absolute
references or relative references for the cells on which you are
clicking. Absolute references make your macro run at the same
cells where you recorded the macro. On the other hand, relative
references make your macro run at the active cell.
• You will learn about these in the chapters - Using Absolute
References for a Macro and Using Relative References for a
Macro.

25-08-2023 Institute of Public Enterprise 13


Macro Code in VBA
• You can record and run macros from Excel even if you do not
know Excel VBA. However, if you have to modify a recorded
macro or create a macro by writing VBA code, you should learn
Excel VBA. You can refer to the Excel VBA tutorial in this tutorials
library for this
• However, you should know how to view the macro code. You can
learn how to access VBA editor in Excel and about the different
parts of the VBA editor in the chapter – Excel VBA.
• You can learn how to view the macro code in Excel VBA editor
and you can understand the macro code in the chapter -
Understanding Macro Code.
25-08-2023 Institute of Public Enterprise 14
Assigning Macros to Objects
• You can assign a macro to an object such as a shape or a
graphic or a control. Then, you can run the macro by clicking on
that object. You will learn about this in the chapter - Assigning
Macros to Objects.

25-08-2023 Institute of Public Enterprise 15


Running Macros
• Excel provides several ways to run a macro. You can choose
the way you want to run a macro. You will learn about these
different possible ways of running a macro in the chapter -
Running a Macro.

25-08-2023 Institute of Public Enterprise 16


Creating a Macro Using VBA Editor
• If you decide to write the macro code, - Creating a Macro Using
VBA Editor. However, the prerequisite is that you should have
Excel VBA knowledge.

25-08-2023 Institute of Public Enterprise 17


Editing a Macro
• You can modify macro code in Excel VBA editor. If you want to
make extensive changes, you should have Excel VBA
knowledge. But, if you want to make only minor changes to the
code or if you want to copy the VBA code from a recorded
macro to another macro, you can refer to the chapter - Editing a
Macro.
• You can rename a macro and even delete it. You will learn
about this also in the same chapter.

25-08-2023 Institute of Public Enterprise 18


User Forms
• A Form is normally used to collect required information. It will be
self-explanatory making the task simple. Excel User Forms
created from Excel VBA editor serve the same purpose,
providing the familiar options such as text boxes, check boxes,
radio buttons, list boxes, combo boxes, scroll bars, etc. as
controls.
• You will learn how to create a User Form and how to use the
different controls in the chapter – User Forms.

25-08-2023 Institute of Public Enterprise 19


Debugging Macro Code
• At times, a macro may not run as expected. You might have
created the macro or you might be using a macro supplied to
you by someone. You can debug the macro code just as you
debug any other code to uncover the defects and correct them.
You will learn about this in the chapter - Debugging Macro
Code.

25-08-2023 Institute of Public Enterprise 20


Configuring a Macro to Run on Opening
a Workbook
• You can make your macro run automatically when you open a
workbook. You can do this either by creating an Auto_Run
macro or by writing VBA code for workbook open event. You will
learn this in the chapter - Configuring a Macro to Run on
Opening a Workbook.

25-08-2023 Institute of Public Enterprise 21

You might also like