Below you will find misc. information that may help you in your work with VBA macros.
Quick Navigation
What is a VBA macro - what is an add-in?
For Visual Studio for Mac, see Code snippets (Visual Studio for Mac). Code snippets are available for a multitude of languages, including C#, C, Visual Basic, XML, and T-SQL, to name a few. To view all the available installed snippets for a language, open the Code Snippets Manager from the Tools menu (or, press Ctrl + K, Ctrl + B ),. To learn more about how Grammarly for Microsoft Office works and to make sure that Grammarly is compatible with your computer, please check this article. Note: If you use macOS, please check this article for more information about Grammarly for Microsoft Word on Mac.
- First of all, open the MS Word document in which you want to insert the code snippet. Then place the cursor where you want the snippet to be inserted. Now, go to Insert tab and then click on the Object option. A new box will appear with a list of objects that you can insert in your MS Word document.
- Snippets make reusing text simple. Just select text – a few words, a whole paragraph, or an entire document – and then create a snippet with one click. Insert snippets with a click or autocomplete as you type. Easily see how text differs from a snippet. Instantly create a new document from snippets.
A macro is an action or a set of actions that can be used to automate tasks.
Macros are created using Microsoft Visual Basic for Applications, also known as VBA. VBA is built into the Office applications.
An add-in is a supplemental program that adds custom commands or features to an application. On this website, you will find information about and links to Word add-ins I have developed. The add-ins are available at wordaddins.com. Some of the add-ins may contain only a few macros whereas others contain hundreds of macros.
Example of macro and the result of running the macro.
Where to find the macro code in the articles
You will find articles with macros and code snippets in the Word Macros menu above and below the Articles With Word Macros heading in the sidebar to the right.
![Word Word](/uploads/1/2/6/6/126694052/550691351.jpg)
Find links to macro code in articles
In most of the Word macro articles, you will find a heading How to get the macro or similar. Below that heading, you will find a box with a link that opens a separate window with the related macro code. See the example below:
You can copy the code from the window that opens and paste it into the Visual Basic Editor. If you paste the code somewhere else, e.g. in a Word document, paste it as unformatted text.
Macro code directly in articles
In some articles, you will find entire macros listed directly in the article or you will find code snippets. All such code is shown with the Courier New font on white background. Avi codec pack. Example:
'Comments in the code are blue
Code is shown with Courier New font on white background like here
Code is shown with Courier New font on white background like here
How to work more efficiently with VBA macros
Below, you will find an introduction to two tools I use when working with VBA and macros.
Smart Indenter - a free add-in for VBA
In order to make VBA code as readable as possible, it is a great help to have the code indented so that the structure is clear. Code you copy and paste from a website or from elsewhere may not be indented properly.
I use the free add-in Smart Indenter from Office Automation Ltd. to handle this.
- PRODUCT INFO AND DOWNLOAD LINK Smart Indenter v3.5
Note that the product page mentions Excel but the add-ins works with Word too.
It is a rather old add-in but it still works, also with Office 2016. I don't remember having any problems with the installation in any version of Office but it may be because I have had MZ-Tools installed first. If you have problems with the installation, the following article may help:
- INSTALLATION HELP Help on Installing Smart Indenter in Office 2013-2016
MZ-Tools – an advanced add-in for VBA
Each time I start using a new computer I am quickly reminded of especially one extremely useful VBA add-in that is missing and that I need to get installed to get up to speed with VBA.
That add-in is MZ-Tools. In the same way as macros can help you be more productive and make better documents in Word, MZ-Tools can help you be more productive and make better code in VBA.
The MZ-tools add-in is developed by Carlos J. Quintero and provides a comprehensive set of tools for VBA (64-bit & 32-bit) plus for Visual Studio (.NET), VB6 and VB5. I use MZ-Tools in relation to VBA.
Originally, MZ-Tools for VBA was free. In October 2015, a new version was released and it is not free anymore which is fair based on the huge amount of features that have been added to the add-in. A 30-day free trial is available.
If you develop VBA macros yourself and if you don't know MZ-Tools already, I recommend you check it out.
- PRODUCT INFO AND DOWNLOAD LINKRead more about MZ-Tools and the features
- DOWNLOAD FREE TRIALDownload free trial of MZ-Tools
Microsoft Office For Mac
Examples of useful features in MZ-Tools
Free Code For Microsoft Word
Below are a few examples of features in MZ-Tools that I use a lot:
Lets you store named snippets of code as code templates you can insert easily – almost as using AutoTexts in Word documents.
Lets you copy and paste controls including the related code (event handlers) from one form to another.
Helps you improve the quality of your code. For example, you can easily find and remove unused declarations in the source code (constants, variables, etc.) and you can find issues where your code does not follow the rules you have specified.
See How to Install a Macro for information about how to install macros.