Word Macros
What's covered?
A selection of Word macros that I have written, been helped with or found.
Word Version Compatibility
These macros were created for the version of Word current at the time. They will most likely work in later versions but as with running any macro, create a back up of your file before you start.
How to Add a Macro
Click on any link below to download the required zip file.
Depending on your operating system and security settings, you will either be prompted to save the zip file or your zip application (e.g. WinZip) will open and display the contents of the zip file.
The zip files each contain a bas file for import into Word via the VBA import function.
In Word, locate the VBA Editor. Try Tools | Macros | VBA Editor OR Alt F11.
Create a new module as shown below. Call it whatever you want.
Then right click the module and select Import. Import whichever macros you want to use.
Then either go to Tools | Macro | Macros, select the macro and click Run OR customise a toolbar and add the macro there.
If you want to see the content of the bas file before importing it into Word, open the file with a text editor such as Notepad.
The Macros
Word Macro |
Action |
||
Puts selection in round brackets () |
|||
Puts selection in quote marks |
|||
Puts selection in html tags <> |
|||
Add Page Numbers after hyperlinks in RoboHelp Printed Documentation Classic Versions only |
In your printed documentation, you may have something like Figure 1 which is fine for anyone viewing the document on a PC. They can click the hyperlink and see Program Access. But what about someone reading hard copy? It's not much use to them is it? They have to go to the Table of Contents and locate "Program Access". Figure 1
Figure 2
The lines r.InsertAfter allow you to define the text surrounding the page number to whatever you want. This requires some thought as you need to find a single string of text that will always work. The string works for my documents regardless of whether the hyperlink is followed by a full stop (period) or a space. If the hyperlink is already followed by something in brackets, then you will end up with text as in Figure 3. Figure 3
The hyperlink is left working for the benefit of anyone viewing the Word document on their PC. Also removing it would destroy the context of your documents. Imagine the examples shown without the hyperlinks being left in place. The usual warning, backup your document before you run the macro. UPDATE 19 Aug 2012. This is what I see after running the macro. Mary Moore advised me that the link was extending to include (See page. I have retested the macro above and do not have that problem but if you do, then you might want to try an alternative macro that was posted at WindowsSecrets.com by Paul Edstein, Microsoft Word MVP. Paul claims this code will also run faster. Click in the field below and then press CTRL + C to add the code to the clipboard. Then create the macro in Word.
Thanks to both HansR and Paul Edstein. |
||
When you import a Word document into RoboHelp, the mapping dialog will show all the styles available in the document. In documents that have passed from person to person, these can be high in number. I have seen one report of 300 styles! You only need to map the used styles rather than those available but not used. Run this macro before you import to remove the unused styles. |
|||
With cursor in a cell with text, the macro copies text to each blank cell below until it finds another value. That value is then copied and the process repeats. |
|||
Seven macros
The above macros have clearly marked sections that apply the formatting so that you can substitute what you want in place of what I use. |
|||
Prints current page. |
|||
Sometimes you will see a heading style one line down from the top of the page when you generate printed output from RoboHelp. Run this macro to remove just those blank lines. |
|||
Removes all bookmarks from a document. Use with care. |
|||
Two macros
|
|||
Word will reduce image sizes to make them fit the page width. In older versions of RoboHelp, any image that is not set to 100% will get converted to a JPG when you or RoboHelp use the Save As Web Page Filtered option. |
|||
This zip file also contain a frm file. See the readme text file. |
Run the Style Changer macro to display the Style Changer dialog. The dialog doesn't do anything more than the standard Find and Replace, it just makes it a lot quicker. Word's Find and Replace function requires ten clicks before the operation starts whereas this requires one click to display the dialog box, then select the two styles and one more click to start the operation. Also Word's function requires you to select from the list or you can type just the first letter of the style. If that does not find the style, you have to scroll down to locate it. This method allows you to keep typing the style name until it is found. |
Donations
If you find the information and tutorials on my site save you time figuring it out for yourself and help improve what you produce, please consider making a small donation.