business-resized-360x450.jpg
In the previous post we demonstrated how you can Record a Word Macro using Word’s ‘Record Macro’ function.  

In many of the posts on this BLOG you will find sample code and Expedience ‘Copy Cat’ macros (that is, macros based on our Software Suite) that cannot be created by using the ‘Record Macro’ technique.  

To use these macros you can simply copy and paste the code into a macro of your own.

In the previous ‘Record Macro’ post we recorded two macros: one to show bookmarks and one to hide them.   In this post we will combine the two macros together to toggle the bookmarks off and on and  then to paste this into your own ‘ToggleBookmarks’ macro.   

First, let’s locate the Macro Dialog box:  
You can find macros on the ‘View Tab’ of the Word Ribbon (2007-2013):
Find Macros Drop-down
From the ‘Macros’ drop-down you can view a list of all of the macros that are currently available to you.
You can also find Macro functions on the ‘Developers’ tab.   (By default this tab is hidden but you can enable it by clicking on ‘File’ .  Select ‘Options’ ,‘Customize Ribbon’, and check the ‘Developers’ tab to true.
Click on ‘View Macros’ to see the two macros we have previously created:
HideBookmarks and ShowBookmarks appear on macro list
If we click the ‘Edit’ button we can see the code behind these macros:
View ShowBookmarks and HideBookmarks macro code.
To make a macro that will toggle between off and on, I can simply set the ShowBookmarks option to its opposite.  Here is the line of code that does that:
ActiveWindow.View.ShowBookmarks =Not(ActiveWindow.View.ShowBookmarks)
Select that line of code and copy it to your clipboard (Control + C).
Go back to the ‘View Macros’ dialog box.  Put your cursor in the ‘Macro Name’ box and type the name of our new macro:  ‘ToggleBookmarks.’    (Remember: do not use spaces or punctuation.)

Click the ‘Create’ button:
Click 'Create' macro to paste ToggleBookmarks code
This will take you to the Macro editor:
Image of macro editor
Place your cursor before the ‘End Sub’ line and paste the line of code that you copied earlier:
Paste ToggleBookmarks into macro editor
Close the macro editor.
Now test the macro.  Select some content and insert a bookmark.  Select the ‘ToggleBookmarks’ from the View Macros list and click ‘Run.’
Here is an example of Bookmarks turned on:
And now turned back off:

 

Recent Articles