Word.Tips.Net Welcome toWord.Tips.Net

Helpful Links

Tips.Net Home
WordTips Home

Ask a Word Question
Make a Comment

Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

Newest Tips

Moving Drawing Objects

Standardizing Note Reference Placement

Selecting Printing of Color Pictures

Stubborn Foreign Languages

Sizing the Preview Pane

Moving Rows and Columns With the Mouse

Searching for Formatting

 

Macros

Tips, Tricks, and Answers

The following articles are available for the 'Macros' topic. Click the article's title (shown in bold) to see the associated article.

Adding a Macro to a Toolbar
One of the easiest ways to quickly access a macro is to assign it to a toolbar button. How you make the assignment depends on the version of Word you are using.

Adding Smart Quotes through Macro Text
When text is added to your document by a macro, and that text includes quotes or apostrophes, Word won't change the quotes or apostrophes to "smart quotes." This tip explains why and shows what you can do about this predicament.

Aligning a Paragraph in a Macro
If you are applying formatting from within a macro, you may want to change the alignment of various paragraphs. Here's how you can do it by adjusting the Alignment property.

Assigning a Macro to a Button in Your Text
Got a macro you want users to be able to access easily? Just attach that macro to a MACROBUTTON field code, and the trigger for the macro will appear directly within the text of the document itself. This tip explains how to set up such a field in your document.

Assigning a Macro to a Keyboard Combination
A quick way to run a macro is to associate a shortcut key combination with the macro, and then use that shortcut to invoke the macro. Assigning shortcuts to macros is easy to do; just follow the steps in this tip.

Assigning a Macro to a Shortcut Key
Macros are very powerful. You can make them handy—in addition to powerful—if you assign a shortcut key to your macros. The process is relatively easy, as this tip documents.

Automatically Inserting Brackets
Want a fast way to add brackets around a selected word? You can use this simple macro to add both brackets in a single step.

Automatically Inserting Tomorrow's Date
Do you routinely need to work with tomorrow's date? Why not create a template that automatically adds tomorrow's date to any point in the document you want. This tip shows how easy this can be.

Batch Template Changes
Changing the Template on a couple of documents is easy, but what if a whole directory needs to be changed? This VBA macro will do it very quickly.

Calculating a Future Date
VBA provides the DateAdd function to perform math on dates. This tip describes how to add and subtract dates to calculate future and past dates.

Changing Between English Variants
What is the easiest way to switch between English spelling variants in a document? This tip examines a couple of ways you can handle the desired conversion.

Changing Directories in a Macro
When a macro works with files, it often has to change between different directories on your disk drive. This is done using the ChDir command, as described in this tip.

Changing the View in File New
Using a Word macro to change the view when selecting New from the File menu.

Checking for a Security Certificate
You can digitally sign your VBA projects to help ensure authenticity of your code and increase security. If you use such signatures, it is a good idea if your macros check to ensure that the signature is present. This tip explains how to do the check in VBA.

Cleaning Up Text in a Macro
Need to remove extraneous characters from a text string? VBA makes it easy through the CleanString method, described in this tip.

Controlling Repagination in Macros
For most Word users, repagination of a document is done automatically, in the background, as you are editing. If the edits are being done by a macro, the background repagination may slow down what the macro is doing. If you want to control repagination, you can use the Pagination property or simply turn off screen updating.

Controlling the Bold Text Attribute
When processing a document in a macro, you may need to make some of your text bold. It's easy to do using the Bold attribute, as described in this tip.

Converting Strings to Numbers
When creating macros, you often need to convert a text string that contains numbers into actual numeric values. You do this by using the Val function, described in this tip.

Converting Text to Uppercase in a Macro
The VBA macro language includes the ability to modify the capitalization of a text selection. There are two ways to perform this conversion, as you discover in this tip.

Counting the Instances of a Text String
Sometimes it is helpful to know how often a particular phrase appears within a document. If you need to know such a count, here's a handy macro you can use to get the desired info.

Creating a Command List
Want a list of all the commands available in Word? You can get one easily by following these steps.

Creating a Directory
Need to create a directory from within a macro? You can do it using a single command line, as detailed in this tip.

Creating a Document Font List
If you need a list of fonts used in a document (as opposed to the fonts installed on a system), then the macro in this tip will be of great use. It quickly allows you to pinpoint if you are missing fonts necessary to properly display the document.

Creating a String
Need to use a macro to create a text string? One easy way to do it is to use the String function, described in this tip.

Creating or Changing Wizards
Wizards are used to programmatically step you through how to create a particular document or create a desired result in Word. You can create your own Wizards or edit existing Wizards if you know the information in this tip.

Determining a Random Value
If you need to determine a random value in a macro, you can do so using the Rnd function. This tip presents the syntax and usage of the function.

Determining an Integer Value
One of the math functions you can use in your macros is the Int function. It provides a way for you to derive an integer value from whatever original values you are working with.

Determining the Horizontal Position of the Insertion Point
Need to figure out how far the insertion point is from the left margin? You can do so by using this small macro that relies on the Information property.

Determining the Length of a String
Need to find out in a macro how long a particular text string is? You can figure it out by using the Len function, described in this tip.

Displaying the Document Title Right Away
One of the properties that Word maintains for a document is a title. If you want this title displayed on the title bar right after opening the document, you'll need the single-line macro described in this tip.

Editing Word's Built-in Commands
Want to configure Word to do just what you want it to? You can even go so far as to change the actual way in which Word performs its internal commands. This tip explains how you use the VBA editor to change those internal commands.

Extracting INCLUDEPICTURE File Names
If you use the INCLUDEPICTURE field to add images to your document, you may love the macro in this tip. It allows you to pull all the filenames used in the field, resulting in a handy image file list.

Finding and Changing Word's Internal Commands
How to locate and change one of Word's internal commands.

Finding Long Lines
Word is very dynamic in how it "flows" text from one line to another and one page to another. In most cases we are willing to allow Word to do its job in this area. In some situations, however, you may need to know if a paragraph has flowed to a new line so that you can "force" it to fit all on one line. Making this determination is not as easy as you might like.

Finding Long Sentences
For certain types of writing, you may want to make sure that the sentences in your document do not exceed a certain limit. Word provides no tool to do this, but you can create your own tool for checking sentence length. This tip shows you how.

Forcing the Date to the Next Wednesday
Working with today's date in Word is easy. Trying to manipulate dates to come up with a future one can be an entirely different story. This tip provides a quick and easy macro that inserts the date of whatever next Wednesday happens to be.

Getting User Input in a Dialog Box
Want to grab some interactive input from a user in your macro? The best way to do that is with the InputBox function, described in this tip.

Highlight Words from a Word List
Do you need to highlight certain words in a document, and aren't quite sure how to go about it? Using the techniques described in this tip, you can create a word list document and then run a macro to highlight all the occurrences of the words in that word list.

How to Paste Non-Floating Pictures with a Macro
Using a macro to paste pictures inline instead of floating in Word 97.

Hyperlinks in an Index
How to establish a hyperlink between an index and the text in a Word document.

Index Number for the Active Table
For some programming needs, it is important to determine the index of an object within a collection of such objects. This tip discusses ways you can determine the index number of a table within the Tables collection.

Inserting a Paragraph from within a Macro
Macros are often used to process documents and make changes to them. This quick tip illustrates the macro code to use when you want to place and end-of-paragraph mark within the document.

Inserting Text with a Macro
Need to have your macro insert a bit of text into your document? It's easy to do using the TypeText method.

Intelligible Names for Macros
The names you use for macros can affect what you see when you add those macros to a toolbar. This tip explains how you can change macro names on toolbars, as well as change the ToolTip that appears for a macro.

Invisible Macros
Where to look for macros that have disappeared from the macro list in Word.

Listing Documents with Passwords
Do you need a list of documents that require a password or that require a particular password to open? Word doesn't provide a way to retrieve such information, but you could do it with a macro. This tip describes the approach that should be used if you decide to develop such a macro.

Macro-Inserted AutoText Doesn't Set Style
Inserting AutoText from a macro can give unwanted results, particularly when it comes to any style that may be stored with the AutoText entry. The solution is to make sure your macro uses the RichText parameter, as described in this tip.

Making Macros Run Faster
Designing a macro to make it run faster.

Making Macros Run Faster, Take Two
A simple way to make your Macros run faster. Part II.

Managing the AutoCorrect List
If you need to delete all the entries in your AutoCorrect list, the easiest way to do so is with a macro. This tip describes just such a macro.

Moving the Insertion Point in a Macro
One of the common things done in macros is to somehow "process" documents, which often means moving the insertion point in some manner. This tip explains how this is most easily done.

Moving the Insertion Point to the Beginning of a Line
If you need to move the insertion point within your macro, then you'll want to note the HomeKey method, described in this tip. It can be used to move the insertion point to the beginning of a line of text.

Numbers to Text, Take Three (Over a Million)
So, you need to convert a number to text that is over one million? Here is a VBA macro that will convert up to 999,999,999.

Occurrences of a Text String within a Document
You may have a need to find out how many times a certain text string occurs within a document. You can find out manually using the Find and Replace features of Word, but that won't work in a macro. The technique in this tip will work, however.

Offering Options in a Macro
When creating macros, you often need to offer a series of choices to a user. This tip demonstrates how easy it is to offer options and get feedback, using just a few commands.

Options in Opening Files
Changing the standard shortcut for opening a New File.

Passwords for Creating Macros
What to do if Word starts asking for a password to create a macro.

Printing and Exiting Word in a Macro
When you print a document, Word remains busy in the background until the printing is done. If you try to end the program before printing is done, you can cause problems for your printout. This tip explains how to bypass the potential problem by making just a small change to how the document is printed.

Printing Shortcut Key Assignments from a Macro
Adding a line to your Macro to print out your shortcut keys is as easy as one line.

Printing Styles in a Macro
Using a Macro to print out a list of styles.

Printing Summary Information from a Macro
Part of the information that Word maintains about each of your documents is a summary statement, which you can define in the properties for the document. If you want to print that summary from within a macro, you can use the .PrintOut method, described in this tip.

Printing via Macro without Messages
When you are printing a document, it is not unusual to see messages (dialog boxes) periodically. When you want the printing to be done by a macro, the messages can cause unwanted interruptions. Here's a way to make the messages stop.

Problem With Add-on Macros
Add-ons for Word normally use macros to perform the tasks for which they were designed. If you suspect that you are having problems with add-on macros in Word, then you may need to apply some of the techniques in this tip to uncover what is going on.

Quickly Dumping Array Contents
A VBA macro that will erase all of the information in your array.

Quickly Switching Languages
Setting up macros to switch between languages easily.

Removing a Directory
Your macro, in the course of doing some processing, may create a directory that you later need to delete. Here's how to get rid of it.

Removing All Text Boxes In a Document
Got a lot of text boxes you need removed from your document? There are a number of ways you can get rid of them, as this tip explains.

Renaming a File
Need to rename a disk file from within a macro? You can do it using the Name command, described in this tip.

Repaginating in a Macro
Do you need your macro to repaginate a document? Use the .Repaginate method, as described in this tip.

Repaginating Your Document in a Macro
Macros can be used to do extensive processing on a document. After the processing, you may want to repaginate the document. You can do so using the Repaginate method, as described here.

Resetting Character Formatting in a Macro
Want your macro to get rid of the formatting applied to a selection of text? It's easy enough to do using the Reset method, described in this tip.

Reversing a String
Need to reverse all the characters in a string? You can do so by using your own function that does the heavy lifting for you.

Running Macros from Macros
Need to run one macro from within another macro? You can easily do it by using the Run method of the Application object, as described in this tip.

Safely Relocking Forms
In order to use a form in Word, it must be protected. This means that you cannot make any changes to the form, even if you need to. If you unlock the form to make changes, then when you relock it, the data in the form is wiped out. This tip provides a solution you can use to safely relock your forms without losing data.

Searching for Adjectives and Adverbs
Searching for different types of words in your documents is a nice thing to contemplate, but it is much harder to do in reality. The English language has enough vagaries that it can be challenging.

Setting a VBA Variable From a Bookmark
Bookmarks are a great way to mark a memorable place in a document. When processing a document using macro, you may want to assign some bookmarked text to a variable. This tip explains how to retrieve the desired bookmark information.

Setting the Left Indent of a Paragraph in a Macro
When using a macro to format text, you can set all sorts of attributes for paragraphs or individual characters. On attribute you can specify is how far the left margin of the paragraph should be indented. All it takes is a single command, as described in this tip.

Setting the Right Indent of a Paragraph in a Macro
Need to format your document using a macro? You can easily set the right margin for an individual paragraph by using the RightIndent property, described in this tip.

Suppressing the Control Toolbox Toolbar
If the Control Toolbox keeps appearing when you open a document, it can be bothersome. This tip explains why this may happen and what you can do to get rid of the toolbox, once and for all.

Swapping Two Strings
Part of developing macros is learning how to use and manipulate variables. This tip examines a technique you can use to exchange the contents of two string variables.

Temporarily Changing the Printer in a Macro
If you use a macro to print to a specific printer, that printer becomes the default printer for Word from then on. (Well, at least until you explicitly change the printer.) With the quick technique described in this tip, you can print to any printer you want without the user ever being aware that you had changed from the printer he or she had previously selected.

Toggling Font Assignments in a Macro
If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This tip presents such a macro, along with an alternative method of quickly changing typefaces.

Understanding the While...Wend Structure
One of the basic programming structures used in VBA is the While ... Wend structure. This structure helps to make the controlled repeating of programming statements quite easy.

Using AutoCorrect to Start Macros
As you are typing, AutoCorrect provides a "check" that what you are entering doesn't match some pre-defined error triggers. The idea is to make sure your text reflects what you intended to write, rather than what you really wrote. This tip discusses the concept of whether AutoCorrect can be used to not only "fix" what you type, but also start macros that could do even more processing.

Using Mandatory Form Fields
Form fields can be used to create specialized forms in Word, which are very handy for collecting information. This tip explains some techniques you can use to ensure that some of your form fields are filled in by the user.

Word's Object Model
Understanding Word's Object Model and how it relates to macros in VBA.

Working With Multiple Printers Using WordBasic
Setting up an icon on your toolbar for each Printer you use.

 

More Information

The following are additional topics related to the subject of 'Macros'. A bracketed number after the topic indicates how many articles are related to that subject.