SlideShare a Scribd company logo
1 of 33
Prepared By: Er. Nawaraj
Bhandari
Office Solution And Development
Chapter:5
An Introduction to VBA and
Macros
What is a Macro?
 A macro is made up of a series of instructions
which are recorded so that they can be played
back later and this can be done by a single
keystroke or command. These commands can act
as a shortcut to enable repetitive tasks to be
completed more efficiently and quickly.
 They can be run from a button, toolbar or menu.
 Event macros are started by an event, such as
double clicking a cell, opening a workbook, or
activating a worksheet.
Why are Macros Used?
 Macros can be used to automate and add functionality to
many tasks, such as:
 formatting whole or parts of documents,
worksheets,
 graphs
 re-organising data
 templates
 formatting and reports
 changing values of stored data
 error message notification
 interactive user forms/boxes, e.g. data entry
How are Macros Developed?
 There are two ways to develop macros:
 The easiest method is to use the Macro Recorder
to record a sequence of instructions selected by a
user. An application, such as Excel or Word
stores information about each of the steps taken
by a user as they record their commands. The
macro can then be run to repeat these
commands.
 Another method is for a user to write instructions
using the VBA programming language.
How Macros are Record?
What is VBA?
 VBA stands for Visual Basic for Applications and
is a programming language.
 It has its own integrated development
environment within Microsoft Office called the VB
(Visual Basic) Editor.
 Macros can be developed using it, their instructions
written in the VB Editor instead of being recorded
by the Macro Recorder.
 Note that when a macro is developed using a
Macro Recorder, a VBA program is written in the
background and this program can be read in the
Macros and Security
 Macros are subject to security problems,
such as viruses, which are frequently
attached to software downloads hidden in
the code of macros.
 Always ensure that your security settings
are set appropriately – see
http://office.microsoft.com/en-us/
Applying Security Levels
 Apply security settings by selecting the following:
1
2
Selecting Security Levels
• The second selection
is generally
recommended.
The Visual Basic Environment
 The Visual Basic Editor is
a program within Excel and
Word that allows you to
communicate with Excel
and Word by writing specific
instructions or code.
Selecting the VB Editor
• This can be done either by:
- Selecting the Developer option from the Ribbon
- Selecting Visual Basic
OR
• Or simply pressing the ALT key and the F11 key
The VB Editor
 This is the VB Editor
window.
 Click on the two
to close the two
windows if they are
open.
The VB Editor Screen
 The VB editor
screen will now be
displayed.
 To work efficiently in
the VB Editor, there
are three windows
that should be
displayed and they
can be set up as
follows:
The VB Editor Windows
- Project Window
(Project
Explorer)
- Code Window
- Properties Window
We will discuss each in turn
Setting up the Project Window
 Select View from the
main menu bar.
 Select Project Explorer
 The Project Window will
be displayed.
The Project Window
 This lists the projects
and sheets (modules)
and user forms.
Setting up the Properties Window
 Select View from the
main
menu bar
 Select Properties
Window
 The Properties
Window will be
displayed
The Properties Window
 This displays the
properties of the object
that is selected, e.g. the
worksheet or the
properties of control
commands, e.g.
command buttons, list
boxes, etc. on user
forms.
Setting up the Code Window
 Double click on the
name of
a component in the
Project
window (Sheet1,
Sheet2,
etc.)
 You can also select it
via the
View option on the
menu
and selecting the Code
The Code Window
The Code Window
 Macro and VBA code is
written and edited here.
 The font style and colour
cannot be changed here.
 Text and figures are
displayed in black.
 Comments are displayed in
green, reserved words
display in blue and error
messages appear in red.
Writing a Macro
 Ensure that the Code Window for Sheet 1 is
displayed.
 We will enter a simple macro that contains
instructions to add together two values and
display the total.
 We have to ensure that we enter all text,
figures, quotation marks, full stops,
brackets, equal signs and spaces
accurately.
Macro Instructions
The first line presents the name of
the program (user defined) always
starts with Sub
Running the Macro
 Select Run from the menu
bar at the top of the VB
Editor screen.
 Select Run.
 Select Run Macro.
 Run the macro.
 Press ALT and F11.
The Macro Result
 The two values have been
added and the total
Calculated.
How to Run the Macro from the Menu Bar
- 1
 In Sheet 1, delete the figures in cells A1, A2 and
A3.
 Select View from the Ribbon.
 Select Macros.
 In the dialogue box, select Sheet1.macroFormula.
 Select Run.
How to Run the Macro from the
Menu Bar - 2
1
2
3
Result of Running the Macro from
the Menu Bar
Macro Comments
 A macro comment is a piece of text in a macro
which will not be executed; it is included to provide
the user with information and is displayed in green.
 To let the Visual Basic Editor know that it is a
comment, place an apostrophe at the start of the
text.
e.g. 'This next instruction will add the two
values
Range("A3").Formula = "=A1+A2“
 Comments become more useful if programs
become more complex and it is good practice to
use them.
Saving a Macro
 This can be done within the VB Editor
 Use relevant names
 There should be no spaces in between
words.
Editing a Macro in the VB Editor
 Select the macro from the list in the Project
Window.
 All changes can be made to an existing macro in
the VB Editor Code Window.
References - 1
 Gonzalez, J., Meister, C., Ozgur, S., Dilworth, B., Troy, A.
and Brandt, T. (2006). Office VBA Macros You Can Use
Today: Over 100 Amazing Ways to Automate Word, Excel,
PowerPoint, Outlook & Access. Holy Macroi Press.
ISBN-10: 1932802061
ISBN-13: 978-1932802061
 Jelen, B. and Syrstad. T. (2004). VBA and Macros for
Microsoft Excel. Pearson QUE.
ISBN-10: 0789731290
ISBN-13: 978-0789731296
References - 2
 Krieger, S. (2011). Macros Demystified: what they are and
why to use them. [Available Online]
http://office.microsoft.com/en-us/help/macros-demystified-
what-they-are-and-why-to-use-them-HA010007210.aspx
 McFedries, P. (2007). VBA for the 2007 Microsoft Office
System. Pearson QUE.
ISBN-10: 0789736675
ISBN-13: 978-0789736673
 Walkenbach J. (2004). Excel VBA Programming for
Dummies. Wiley Publishing, Inc.
ISBN: 5000024675
Topic 5 – An Introduction to VBA and
Macros
Any Questions?

More Related Content

What's hot

Using vlookup in excel
Using vlookup in excelUsing vlookup in excel
Using vlookup in excel
megankilb
 

What's hot (20)

E learning excel vba programming lesson 1
E learning excel vba programming  lesson 1E learning excel vba programming  lesson 1
E learning excel vba programming lesson 1
 
Introduction to Excel VBA/Macros
Introduction to Excel VBA/MacrosIntroduction to Excel VBA/Macros
Introduction to Excel VBA/Macros
 
A Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroA Quick Simple MS Excel Macro
A Quick Simple MS Excel Macro
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
Excel training
Excel trainingExcel training
Excel training
 
Excel VBA programming basics
Excel VBA programming basicsExcel VBA programming basics
Excel VBA programming basics
 
Basic Ms excel
Basic Ms excelBasic Ms excel
Basic Ms excel
 
Excel Macro Magic
Excel Macro MagicExcel Macro Magic
Excel Macro Magic
 
Excel formulas tf-jul1605
Excel formulas tf-jul1605Excel formulas tf-jul1605
Excel formulas tf-jul1605
 
E learning excel vba programming lesson 3
E learning excel vba programming  lesson 3E learning excel vba programming  lesson 3
E learning excel vba programming lesson 3
 
Microsoft Excel - Macros
Microsoft Excel - MacrosMicrosoft Excel - Macros
Microsoft Excel - Macros
 
Presentation
PresentationPresentation
Presentation
 
Introduction to MS excel
Introduction to MS excelIntroduction to MS excel
Introduction to MS excel
 
Vlookup - an introduction
Vlookup - an introductionVlookup - an introduction
Vlookup - an introduction
 
M.S EXCEL
M.S EXCELM.S EXCEL
M.S EXCEL
 
Microsoft Excel Basics
Microsoft Excel BasicsMicrosoft Excel Basics
Microsoft Excel Basics
 
22 Excel Basics
22 Excel Basics22 Excel Basics
22 Excel Basics
 
Excel macro
Excel macroExcel macro
Excel macro
 
Using vlookup in excel
Using vlookup in excelUsing vlookup in excel
Using vlookup in excel
 
Microsoft Excel- basics
Microsoft Excel-  basicsMicrosoft Excel-  basics
Microsoft Excel- basics
 

Similar to An introduction to vba and macros

Form4 cd4
Form4 cd4Form4 cd4
Form4 cd4
smktsj2
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
rjg_vijay
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-step
namtranvanpt
 

Similar to An introduction to vba and macros (20)

Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Using macros in microsoft access
Using macros in microsoft accessUsing macros in microsoft access
Using macros in microsoft access
 
VBA
VBAVBA
VBA
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
Using macros in microsoft excel part 2
Using macros in microsoft excel   part 2Using macros in microsoft excel   part 2
Using macros in microsoft excel part 2
 
Form4 cd4
Form4 cd4Form4 cd4
Form4 cd4
 
Notacd04
Notacd04Notacd04
Notacd04
 
Notacd04
Notacd04Notacd04
Notacd04
 
Working with Excel Macros
Working with Excel MacrosWorking with Excel Macros
Working with Excel Macros
 
Exploring Adobe Flex
Exploring Adobe Flex Exploring Adobe Flex
Exploring Adobe Flex
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
VBA Tips
VBA TipsVBA Tips
VBA Tips
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
VBA
VBAVBA
VBA
 
ArduinoWorkshop2.pdf
ArduinoWorkshop2.pdfArduinoWorkshop2.pdf
ArduinoWorkshop2.pdf
 
Visusual basic
Visusual basicVisusual basic
Visusual basic
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-step
 

More from Er. Nawaraj Bhandari

More from Er. Nawaraj Bhandari (20)

Data mining approaches and methods
Data mining approaches and methodsData mining approaches and methods
Data mining approaches and methods
 
Research trends in data warehousing and data mining
Research trends in data warehousing and data miningResearch trends in data warehousing and data mining
Research trends in data warehousing and data mining
 
Mining Association Rules in Large Database
Mining Association Rules in Large DatabaseMining Association Rules in Large Database
Mining Association Rules in Large Database
 
Introduction to data mining and data warehousing
Introduction to data mining and data warehousingIntroduction to data mining and data warehousing
Introduction to data mining and data warehousing
 
Data warehouse testing
Data warehouse testingData warehouse testing
Data warehouse testing
 
Data warehouse physical design
Data warehouse physical designData warehouse physical design
Data warehouse physical design
 
Data warehouse logical design
Data warehouse logical designData warehouse logical design
Data warehouse logical design
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data mining
 
Chapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionChapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean Function
 
Chapter 6: Sequential Logic
Chapter 6: Sequential LogicChapter 6: Sequential Logic
Chapter 6: Sequential Logic
 
Chapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSIChapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSI
 
Chapter 4: Combinational Logic
Chapter 4: Combinational LogicChapter 4: Combinational Logic
Chapter 4: Combinational Logic
 
Chapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic GatesChapter 2: Boolean Algebra and Logic Gates
Chapter 2: Boolean Algebra and Logic Gates
 
Chapter 1: Binary System
 Chapter 1: Binary System Chapter 1: Binary System
Chapter 1: Binary System
 
Introduction to Electronic Commerce
Introduction to Electronic CommerceIntroduction to Electronic Commerce
Introduction to Electronic Commerce
 
Evaluating software development
Evaluating software developmentEvaluating software development
Evaluating software development
 
Testing software development
Testing software developmentTesting software development
Testing software development
 
Application software and business processes
Application software and business processesApplication software and business processes
Application software and business processes
 
An introduction to end user software development
An introduction to end user software developmentAn introduction to end user software development
An introduction to end user software development
 
Advanced features of ms office packages 1
Advanced features of ms office packages 1Advanced features of ms office packages 1
Advanced features of ms office packages 1
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

An introduction to vba and macros

  • 1. Prepared By: Er. Nawaraj Bhandari Office Solution And Development Chapter:5 An Introduction to VBA and Macros
  • 2. What is a Macro?  A macro is made up of a series of instructions which are recorded so that they can be played back later and this can be done by a single keystroke or command. These commands can act as a shortcut to enable repetitive tasks to be completed more efficiently and quickly.  They can be run from a button, toolbar or menu.  Event macros are started by an event, such as double clicking a cell, opening a workbook, or activating a worksheet.
  • 3. Why are Macros Used?  Macros can be used to automate and add functionality to many tasks, such as:  formatting whole or parts of documents, worksheets,  graphs  re-organising data  templates  formatting and reports  changing values of stored data  error message notification  interactive user forms/boxes, e.g. data entry
  • 4. How are Macros Developed?  There are two ways to develop macros:  The easiest method is to use the Macro Recorder to record a sequence of instructions selected by a user. An application, such as Excel or Word stores information about each of the steps taken by a user as they record their commands. The macro can then be run to repeat these commands.  Another method is for a user to write instructions using the VBA programming language.
  • 5. How Macros are Record?
  • 6. What is VBA?  VBA stands for Visual Basic for Applications and is a programming language.  It has its own integrated development environment within Microsoft Office called the VB (Visual Basic) Editor.  Macros can be developed using it, their instructions written in the VB Editor instead of being recorded by the Macro Recorder.  Note that when a macro is developed using a Macro Recorder, a VBA program is written in the background and this program can be read in the
  • 7. Macros and Security  Macros are subject to security problems, such as viruses, which are frequently attached to software downloads hidden in the code of macros.  Always ensure that your security settings are set appropriately – see http://office.microsoft.com/en-us/
  • 8. Applying Security Levels  Apply security settings by selecting the following: 1 2
  • 9. Selecting Security Levels • The second selection is generally recommended.
  • 10. The Visual Basic Environment  The Visual Basic Editor is a program within Excel and Word that allows you to communicate with Excel and Word by writing specific instructions or code.
  • 11. Selecting the VB Editor • This can be done either by: - Selecting the Developer option from the Ribbon - Selecting Visual Basic OR • Or simply pressing the ALT key and the F11 key
  • 12. The VB Editor  This is the VB Editor window.  Click on the two to close the two windows if they are open.
  • 13. The VB Editor Screen  The VB editor screen will now be displayed.  To work efficiently in the VB Editor, there are three windows that should be displayed and they can be set up as follows:
  • 14. The VB Editor Windows - Project Window (Project Explorer) - Code Window - Properties Window We will discuss each in turn
  • 15. Setting up the Project Window  Select View from the main menu bar.  Select Project Explorer  The Project Window will be displayed.
  • 16. The Project Window  This lists the projects and sheets (modules) and user forms.
  • 17. Setting up the Properties Window  Select View from the main menu bar  Select Properties Window  The Properties Window will be displayed
  • 18. The Properties Window  This displays the properties of the object that is selected, e.g. the worksheet or the properties of control commands, e.g. command buttons, list boxes, etc. on user forms.
  • 19. Setting up the Code Window  Double click on the name of a component in the Project window (Sheet1, Sheet2, etc.)  You can also select it via the View option on the menu and selecting the Code The Code Window
  • 20. The Code Window  Macro and VBA code is written and edited here.  The font style and colour cannot be changed here.  Text and figures are displayed in black.  Comments are displayed in green, reserved words display in blue and error messages appear in red.
  • 21. Writing a Macro  Ensure that the Code Window for Sheet 1 is displayed.  We will enter a simple macro that contains instructions to add together two values and display the total.  We have to ensure that we enter all text, figures, quotation marks, full stops, brackets, equal signs and spaces accurately.
  • 22. Macro Instructions The first line presents the name of the program (user defined) always starts with Sub
  • 23. Running the Macro  Select Run from the menu bar at the top of the VB Editor screen.  Select Run.  Select Run Macro.  Run the macro.  Press ALT and F11.
  • 24. The Macro Result  The two values have been added and the total Calculated.
  • 25. How to Run the Macro from the Menu Bar - 1  In Sheet 1, delete the figures in cells A1, A2 and A3.  Select View from the Ribbon.  Select Macros.  In the dialogue box, select Sheet1.macroFormula.  Select Run.
  • 26. How to Run the Macro from the Menu Bar - 2 1 2 3
  • 27. Result of Running the Macro from the Menu Bar
  • 28. Macro Comments  A macro comment is a piece of text in a macro which will not be executed; it is included to provide the user with information and is displayed in green.  To let the Visual Basic Editor know that it is a comment, place an apostrophe at the start of the text. e.g. 'This next instruction will add the two values Range("A3").Formula = "=A1+A2“  Comments become more useful if programs become more complex and it is good practice to use them.
  • 29. Saving a Macro  This can be done within the VB Editor  Use relevant names  There should be no spaces in between words.
  • 30. Editing a Macro in the VB Editor  Select the macro from the list in the Project Window.  All changes can be made to an existing macro in the VB Editor Code Window.
  • 31. References - 1  Gonzalez, J., Meister, C., Ozgur, S., Dilworth, B., Troy, A. and Brandt, T. (2006). Office VBA Macros You Can Use Today: Over 100 Amazing Ways to Automate Word, Excel, PowerPoint, Outlook & Access. Holy Macroi Press. ISBN-10: 1932802061 ISBN-13: 978-1932802061  Jelen, B. and Syrstad. T. (2004). VBA and Macros for Microsoft Excel. Pearson QUE. ISBN-10: 0789731290 ISBN-13: 978-0789731296
  • 32. References - 2  Krieger, S. (2011). Macros Demystified: what they are and why to use them. [Available Online] http://office.microsoft.com/en-us/help/macros-demystified- what-they-are-and-why-to-use-them-HA010007210.aspx  McFedries, P. (2007). VBA for the 2007 Microsoft Office System. Pearson QUE. ISBN-10: 0789736675 ISBN-13: 978-0789736673  Walkenbach J. (2004). Excel VBA Programming for Dummies. Wiley Publishing, Inc. ISBN: 5000024675
  • 33. Topic 5 – An Introduction to VBA and Macros Any Questions?