SlideShare a Scribd company logo
1 of 32
VBA for Technical Writers a.k.a what to do when the macro recorder isn’t enough Adrian Morse Documentation Manager at Picis
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
[object Object],[object Object],[object Object],The Macro Recorder:  Introduction
[object Object],[object Object],[object Object],[object Object],The Macro Recorder:  Limitations
The blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
[object Object],[object Object],[object Object],The VBA Editor:  The  project pane i
[object Object],[object Object],[object Object],[object Object],The VBA Editor:  The  project pane ii
Macros start with “Sub” Comments added automatically Actions performed  by the user Macro name The VBA Editor:  Inside the blue monkey Macros end with “End Sub”
The  bold  blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
[object Object],[object Object],[object Object],[object Object],Basic VBA Concepts:  Objects i
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Basic VBA Concepts:  Objects ii
[object Object],[object Object],[object Object],Basic VBA Concepts:  Object analogy You can think of an object like a car…
Basic VBA Concepts:  Methods and properties Selection.Font. Color Selection. TypeText Object s Method Property ,[object Object]
Basic VBA Concepts:  Events ,[object Object],[object Object],[object Object],… causes this message box to be shown when the document is opened
[object Object],Basic VBA Concepts:  Getting help ,[object Object],[object Object]
The  responsive  blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
Adding a User Interface:  What you can do
The  inquisitive  blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],Topics
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Adding Intelligence:  Loops i Repeating the code is called  looping . There are many ways to do it. This example shows a simple ‘For…Next’ loop.  Means “repeat the code below  for each value of x between 1 and10”.
The  loopy  blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Adding Intelligence:  Loops ii In this loop we increase the font size by 2 points each loop
The  increasingly loopy  blue monkey DEMO
[object Object],[object Object],Adding Intelligence:  Conditions There are different ways to apply conditions. This example shows a simple ‘If…Then’ loop  If ActiveDocument.Name = "Blue.docm" Then  Else: MsgBox (“Rename the document to Blue.docm") End If Means “run the code below if the document file name is  Blue.docm  ” Means “otherwise (if the document is not named  Blue.docm ) show this message…
The  conditional  blue monkey DEMO
[object Object],[object Object],[object Object],[object Object],[object Object],Key Points to Remember Great for getting started but many limitations ALT+F11  opens the editor Macros are based on  objects  that have  properties ,  methods  &  events . You can easily create a GUI and add code “behind” its controls You can enhance code with looping, conditions…
[object Object],[object Object],[object Object],[object Object],What Next?
That’s all folks!

More Related Content

Similar to VBA for Technical Writers: Automate Tasks and Add Interactivity

Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Bill Buchan
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyUna Daly
 
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
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java ProgrammingKaty Allen
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best PraticesChengHui Weng
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applicationsdcoletta
 
2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil MughalAdil Mughal
 
Managing Content Chaos
Managing Content ChaosManaging Content Chaos
Managing Content ChaosChris Campbell
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docxamrit47
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsHakka Labs
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 

Similar to VBA for Technical Writers: Automate Tasks and Add Interactivity (20)

Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
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
 
Mdst 3559-02-10-jquery
Mdst 3559-02-10-jqueryMdst 3559-02-10-jquery
Mdst 3559-02-10-jquery
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Ad507
Ad507Ad507
Ad507
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best Pratices
 
MS Access Macros
MS Access MacrosMS Access Macros
MS Access Macros
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applications
 
2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal2 Day - WPF Training by Adil Mughal
2 Day - WPF Training by Adil Mughal
 
Managing Content Chaos
Managing Content ChaosManaging Content Chaos
Managing Content Chaos
 
PT1420 File Access and Visual Basic .docx
PT1420 File Access and Visual Basic                      .docxPT1420 File Access and Visual Basic                      .docx
PT1420 File Access and Visual Basic .docx
 
Domain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron EdwardsDomain Driven Design in the Browser - Cameron Edwards
Domain Driven Design in the Browser - Cameron Edwards
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Event Programming JavaScript
Event Programming JavaScriptEvent Programming JavaScript
Event Programming JavaScript
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
JS basics
JS basicsJS basics
JS basics
 

More from TCUK

Streamlining the User Assistance Localization Process
Streamlining the User Assistance Localization ProcessStreamlining the User Assistance Localization Process
Streamlining the User Assistance Localization ProcessTCUK
 
On a Mission to Communicate
On a Mission to CommunicateOn a Mission to Communicate
On a Mission to CommunicateTCUK
 
Narrate Your Way To Success
Narrate Your Way To SuccessNarrate Your Way To Success
Narrate Your Way To SuccessTCUK
 
VBA for technical writers - demo script
VBA for technical writers - demo scriptVBA for technical writers - demo script
VBA for technical writers - demo scriptTCUK
 
Content is data: pushing re-use to the limit
Content is data: pushing re-use to the limitContent is data: pushing re-use to the limit
Content is data: pushing re-use to the limitTCUK
 
Rules of thumb for using colour in your content
Rules of thumb for using colour in your contentRules of thumb for using colour in your content
Rules of thumb for using colour in your contentTCUK
 
Make icons make sense: solving symbols for global audiences
Make icons make sense: solving symbols for global audiencesMake icons make sense: solving symbols for global audiences
Make icons make sense: solving symbols for global audiencesTCUK
 
Intuitive images: tips and techniques for creating and evaluating graphics in...
Intuitive images: tips and techniques for creating and evaluating graphics in...Intuitive images: tips and techniques for creating and evaluating graphics in...
Intuitive images: tips and techniques for creating and evaluating graphics in...TCUK
 
M block2 istc_talk_sept2010
M block2 istc_talk_sept2010M block2 istc_talk_sept2010
M block2 istc_talk_sept2010TCUK
 

More from TCUK (9)

Streamlining the User Assistance Localization Process
Streamlining the User Assistance Localization ProcessStreamlining the User Assistance Localization Process
Streamlining the User Assistance Localization Process
 
On a Mission to Communicate
On a Mission to CommunicateOn a Mission to Communicate
On a Mission to Communicate
 
Narrate Your Way To Success
Narrate Your Way To SuccessNarrate Your Way To Success
Narrate Your Way To Success
 
VBA for technical writers - demo script
VBA for technical writers - demo scriptVBA for technical writers - demo script
VBA for technical writers - demo script
 
Content is data: pushing re-use to the limit
Content is data: pushing re-use to the limitContent is data: pushing re-use to the limit
Content is data: pushing re-use to the limit
 
Rules of thumb for using colour in your content
Rules of thumb for using colour in your contentRules of thumb for using colour in your content
Rules of thumb for using colour in your content
 
Make icons make sense: solving symbols for global audiences
Make icons make sense: solving symbols for global audiencesMake icons make sense: solving symbols for global audiences
Make icons make sense: solving symbols for global audiences
 
Intuitive images: tips and techniques for creating and evaluating graphics in...
Intuitive images: tips and techniques for creating and evaluating graphics in...Intuitive images: tips and techniques for creating and evaluating graphics in...
Intuitive images: tips and techniques for creating and evaluating graphics in...
 
M block2 istc_talk_sept2010
M block2 istc_talk_sept2010M block2 istc_talk_sept2010
M block2 istc_talk_sept2010
 

Recently uploaded

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 

Recently uploaded (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 

VBA for Technical Writers: Automate Tasks and Add Interactivity

Editor's Notes

  1. introduction to the Visual Basic for Applications functionality that ships with Microsoft Office products. VBA taster session _______________________
  2. _______________________
  3. _______________________
  4. _______________________
  5. Cannot handle errors - for example, if a macro changes the border colour of a selected table and we run the macro when no table is selected we’ll get an error message. _______________________
  6. The primary objective of the demos is to reinforce the concepts needed to start creating and editing macros. So, realism sacrificed for simplicity. All demos are variations of a simple macro called the blue monkey . _______________________
  7. _______________________
  8. _______________________
  9. _______________________
  10. Comments are ignored when the code is run. When you start editing and creating macros it is good practice to add comments throughout the code. You do this by starting the line with an apostrophe. Note the value for bolding is “wdToggle”. This relates to the limitation– the macro recorder guesses the user’s intentions. It assumes when I clicked the B button on the toolbar while creating macro my intention was to toggle the state of the button rather than to apply bold to the selected text. So, now if I were to click the B button before running the macro the code would toggle the bold off and the word “monkey” would be in regular font. This is not what I wanted. To overcome this I am going to edit the macro. _______________________
  11. First I am going to show you the problem… >Side by side, bold turned off, F8 to run macro. Now bold turned on and run macro again. Now I am going to fix this by changing the selection.font.bold setting. >fix and rerun macro _______________________
  12. _______________________
  13. Last bullet point….The hierarchy is known as the Object Model. Each MS Office application has a different object model. _______________________
  14. You can go a long way without ever needing to create new classes. _______________________
  15. _______________________
  16. This slide shows an example of a method and a property for the object called “Selection”. The Blue Monkey macro code uses this object and in fact the macro recorder often bases its code on this object. Typetext is an action that the object performs. It means it places the text on the page. Color is a property of the selection that can be changed. _______________________
  17. Some objects have events associated with them. Example…the “Document” object can be opened so it has an event called “open” associated with it. VBA makes it particularly easy to access events for the Document object. It does this using the ThisDocument file. This is one of the standard files that I showed you earlier. If you click in the dropdown at the top right you will see a list of the most common event types for the Document object. So you just need to choose the event that you want to trigger your code and then add the code. _______________________
  18. There are various ways to get help with creating macros… Note that Methods and properties are collectively referred to as “members” in the Object Browser and help file. _______________________
  19. _______________________
  20. _______________________
  21. You can add all sorts of controls to a form. It’s easy…you just drag, drop and resize them… _______________________
  22. So now the blue monkey is going to ask us a question…. >Create userform and add code to Thisdocument. Reopen doc. _______________________
  23. There are many ways of adding intelligence to a macro. I am going to talk about two of those: looping and applying conditions.
  24. So we’ve seen that when we record a macro it can set the properties of an object and makes that object do something. Now suppose we want to make that object do something repeatedly. If we had all day to spare we could just record a much longer macro where we repeat tasks over and over again. However, the VB Editor gives us an easy way to repeat a segment of code using a technique called looping . _______________________
  25. So now we’re going to code the blue monkey to repeat itself… >Open yes button code and add For x = 1 to 10, next x …. >Reopen doc ______________________
  26. Now let’s suppose we not only want to repeat the code but we also want to make a change each time the code runs. X is already incrementing by 1 with each loop so we’re going to take advantage of that to increment the point size in the code in the loop. When x is 1 we add 2pts. When x is 2 we add 4pts Etc _______________________
  27. So now I am going to add the code for increasing the font size… >Open yes button code and add change font setting to 24 + 2*x , Reopen the doc…show increasing font size _______________________
  28. Now suppose we only want a segment code to be run in certain conditions. There are various ways to do this. One is with an IF…THEN…ELSE construction. For this example, we only want to run the blue monkey macro if the document filename is Blue.docm…
  29. So now I’m going to edit the macro so that the window only pops up if the document has the name blue.docm. >Add the following to the code in the ThisDocument and reopen If ActiveDocument.Name = "Blue.docm" Then … Else: MsgBox (“Rename the document to Blue.docm") End If >Reopen doc. >Close doc and rename to Blue.docm >Reopen doc. _______________________
  30. _______________________
  31. _______________________
  32. Actually blue monkeys do exist… in Tanzania! _______________________