Applying Formatting to Text
Word Developer Reference |
This topic includes Microsoft Visual Basic examples related to the following tasks:
- Applying formatting to the selection
- Applying formatting to a range
- Inserting text and applying character and paragraph formatting
- Switching the space before a paragraph between 12 points and none
- Switching bold formatting on and off
- Increasing the left margin by 0.5 inch
Applying formatting to the selection
The following example uses the Selection property to apply character and paragraph formatting to the selected text. Use the Font property to access character formatting properties and methods and the ParagraphFormat property to access paragraph formatting properties and methods.
|
Applying formatting to a range
The following example defines a Range object that refers to the first three paragraphs in the active document. The Range is formatted by applying properties of the Font object and the ParagraphFormat object.
|
Inserting text and applying character and paragraph formatting
The following example adds the word "Title" at the top of the current document. The first paragraph is center-aligned and one half-inch space is added after the paragraph. The word "Title" is formatted with 24-point Arial font.
|
Switching the space before a paragraph between 12 points and none
The following example toggles the space-before formatting of the first paragraph in the selection. The macro retrieves the current space before value, and if the value is 12 points, the space-before formatting is removed (the SpaceBefore property is set to zero). If the space-before value is anything other than 12, the SpaceBefore property is set to 12 points.
|
Switching bold formatting on and off
The following example toggles bold formatting of the selected text.
|
Increasing the left margin by 0.5 inch
The following example increases the left and right margins by 0.5 inch. The PageSetup object contains all the page setup attributes of a document (such as left margin, bottom margin, and paper size) as properties. The LeftMargin property is used to return and set the left margin setting. The RightMargin property is used to return and set the right margin setting.
|