David L. answered 05/23/23
SQL expert, fantastic teacher, complete courses or help with 1 query
VBA runs all the in Microsoft Office products except in OneNote. Access also has its own macro utility that is not VBA.
VBA has three parts:
- Part 1: the base VBA language, which is like Visual Basic.
- Declaring variables and their data types with Dim.
- If / ElseIf / Else.
- The various types of loops, such as For and While.
- Functions and Subs.
- et cetera
- Good references for the base language can be found at https://learn.microsoft.com/en-us/office/vba/api/overview/language-reference and at https://learn.microsoft.com/en-us/office/vba/library-reference/concepts/concepts-object-library-reference-for-office.
- Part 2: the so-called "Object Model", which used object-oriented notation and allows you to get access to all the fundamental parts of the Microsoft Office program you're working with:
- In Excel, worksheets, cell values, cell formatting.
- In Access, rows in Access tables.
- In Word, the contents of Word Documents.
- In Outlook, emails, contacts, calendar items, et cetera.
- VBA also runs in PowerPoint, Project, Publisher, and Visio, but not in OneNote.
- In all the Microsoft programs, any VBA forms you create.
- You cannot figure out the Object Model on your own, but If you use your favorite search engine or go to https://learn.microsoft.com/en-us/office/vba/api/overview, you can easily find lots of reference materials and code samples for you to use. VBA is very widely used, and no matter what you want to do, someone else has asked for help on that topic.
- Part 3: VBA can also access COM objects built into Microsoft Windows.
- In Excel, Word, Visio and Project, it is possible to record a macro. If you want to know the VBA for doing a particular action, just take that action while recording a macro. Then stop recording the macro, and edit the new macro, and you will see VBA for doing everything you did in that Office program while recording that macro.
- Unfortunately, recording macros is not possible in Outlook, Access, PowerPoint, or Publisher.