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

Excel PowerPoint
Excel PowerPointExcel PowerPoint
Excel PowerPointnhumar
 
ms excel presentation...
ms excel presentation...ms excel presentation...
ms excel presentation...alok1994
 
A Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroA Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroPranav Ghode
 
Introduction to microsoft office
Introduction to microsoft officeIntroduction to microsoft office
Introduction to microsoft officeTimesRide
 
MS-EXCEL Assignment Help
MS-EXCEL Assignment HelpMS-EXCEL Assignment Help
MS-EXCEL Assignment HelpRahul Kataria
 
Microsoft word - teaching slides
Microsoft word  - teaching slidesMicrosoft word  - teaching slides
Microsoft word - teaching slidesMiss-Short
 
Microsoft Excel Basics
Microsoft Excel BasicsMicrosoft Excel Basics
Microsoft Excel BasicsCompudon
 
Ms excel ppt presentation
Ms excel ppt presentationMs excel ppt presentation
Ms excel ppt presentationvethics
 
Introduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 TutorialIntroduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 TutorialSpreadsheetTrainer
 
Introduction to MS excel
Introduction to MS excelIntroduction to MS excel
Introduction to MS excelfatimazaheer12
 
MS Excel Learning for PPC Google AdWords Training Course
MS Excel Learning for PPC Google AdWords Training CourseMS Excel Learning for PPC Google AdWords Training Course
MS Excel Learning for PPC Google AdWords Training CourseRanjan Jena
 
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 3Vijay Perepa
 

What's hot (20)

Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 
Excel PowerPoint
Excel PowerPointExcel PowerPoint
Excel PowerPoint
 
Ms excel
Ms excelMs excel
Ms excel
 
Vba
Vba Vba
Vba
 
ms excel presentation...
ms excel presentation...ms excel presentation...
ms excel presentation...
 
Excel training
Excel trainingExcel training
Excel training
 
A Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroA Quick Simple MS Excel Macro
A Quick Simple MS Excel Macro
 
Introduction to microsoft office
Introduction to microsoft officeIntroduction to microsoft office
Introduction to microsoft office
 
Microsoft Excel Basics
Microsoft Excel BasicsMicrosoft Excel Basics
Microsoft Excel Basics
 
MS-EXCEL Assignment Help
MS-EXCEL Assignment HelpMS-EXCEL Assignment Help
MS-EXCEL Assignment Help
 
Microsoft word - teaching slides
Microsoft word  - teaching slidesMicrosoft word  - teaching slides
Microsoft word - teaching slides
 
Microsoft Excel Basics
Microsoft Excel BasicsMicrosoft Excel Basics
Microsoft Excel Basics
 
Ms excel ppt presentation
Ms excel ppt presentationMs excel ppt presentation
Ms excel ppt presentation
 
Introduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 TutorialIntroduction to Excel - Excel 2013 Tutorial
Introduction to Excel - Excel 2013 Tutorial
 
Excel Macro Magic
Excel Macro MagicExcel Macro Magic
Excel Macro Magic
 
Introduction to MS excel
Introduction to MS excelIntroduction to MS excel
Introduction to MS excel
 
MS Excel Learning for PPC Google AdWords Training Course
MS Excel Learning for PPC Google AdWords Training CourseMS Excel Learning for PPC Google AdWords Training Course
MS Excel Learning for PPC Google AdWords Training Course
 
Ms word
Ms wordMs word
Ms word
 
Ms excel 2016_function
Ms excel 2016_functionMs excel 2016_function
Ms excel 2016_function
 
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
 

Similar to An introduction to vba and macros

Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical ToolsJoselito Perez
 
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 1guest38bf
 
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 2Er. Nawaraj Bhandari
 
Form4 cd4
Form4 cd4Form4 cd4
Form4 cd4smktsj2
 
Exploring Adobe Flex
Exploring Adobe Flex Exploring Adobe Flex
Exploring Adobe Flex senthil0809
 
Programming basics
Programming basicsProgramming basics
Programming basicsSenri DLN
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1rupeshkanu
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lecturesmarwaeng
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_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-stepnamtranvanpt
 

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

Data mining approaches and methods
Data mining approaches and methodsData mining approaches and methods
Data mining approaches and methodsEr. Nawaraj Bhandari
 
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 miningEr. Nawaraj Bhandari
 
Mining Association Rules in Large Database
Mining Association Rules in Large DatabaseMining Association Rules in Large Database
Mining Association Rules in Large DatabaseEr. Nawaraj Bhandari
 
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 warehousingEr. Nawaraj Bhandari
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data miningEr. Nawaraj Bhandari
 
Chapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionChapter 3: Simplification of Boolean Function
Chapter 3: Simplification of Boolean FunctionEr. Nawaraj Bhandari
 
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 LSIEr. Nawaraj Bhandari
 
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 GatesEr. Nawaraj Bhandari
 
Introduction to Electronic Commerce
Introduction to Electronic CommerceIntroduction to Electronic Commerce
Introduction to Electronic CommerceEr. Nawaraj Bhandari
 
Application software and business processes
Application software and business processesApplication software and business processes
Application software and business processesEr. Nawaraj Bhandari
 
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 developmentEr. Nawaraj Bhandari
 
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 1Er. 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

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
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Ữ Â...Nguyen Thanh Tu Collection
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Celine George
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxakanksha16arora
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 

Recently uploaded (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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Ữ Â...
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

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?