Miscellaneous Tasks
Word Developer Reference |
This topic includes Microsoft Visual Basic examples for the following tasks:
- Changing the view
- Setting text in a header or footer
- Setting options
- Changing the document layout
- Looping through paragraphs in a document
- Customizing menus and toolbars
Changing the view
The View object includes properties and methods related to view attributes (such as show all, field shading, and table gridlines) for a window or pane. The following example changes the view to print view.
|
Setting text in a header or footer
The HeaderFooter object is returned by the Headers, Footers, and HeaderFooter properties. The following example changes the text of the current page header.
|
This example creates a Range object (
|
) that references the primary footer for the first section in the active document. After the Range object is set, the existing footer text is deleted. The FILENAME field is added to the footer along with two tabs and the AUTHOR field.
|
Setting options
The Options object includes properties that correspond to optional settings that are available in various menus and dialogs throughout Microsoft Office Word. The following example sets three application settings for Word.
|
Changing the document layout
The PageSetup contains all the page setup attributes of a document (such as left margin, bottom margin, and paper size) as properties. The following example sets the margin values for the active document.
|
Looping through paragraphs in a document
This example loops through all of the paragraphs in the active document. If the space-before setting for a paragraph is 6 points, this example changes the spacing to 12 points.
|
For more information, see Looping through a collection.
Customizing menus and toolbars
The CommandBar object represents both menus and toolbars. Use the CommandBars property with a menu or toolbar name to return a single CommandBar object. The Controls property returns a CommandBarControls object that refers to the items on the specified command bar. The following example adds the Word Count command to the Standard menu.
|
The following example adds the Double Underline command to the Formatting toolbar.
|
Turn on the macro recorder and customize a menu or toolbar to determine the ID value for a particular command (for example, ID 60 is the Double Underline command).