Format related procedures in class Document (Word VBA)

This page presents procedures from class Document related to the theme Format: ActiveTheme, ActiveWritingStyle, ApplyQuickStyleSet2, ApplyTheme, AutoFormat, AutoFormatOverride, ClickAndTypeParagraphStyle, CopyStylesFromTemplate, DefaultTableStyle, DefaultTabStop, DocumentTheme, DoNotEmbedSystemFonts, EmbedTrueTypeFonts, EnforceStyle, FormattingShowClear, FormattingShowFont, FormattingShowNextLevel, FormattingShowNumbering, FormattingShowParagraph, FreezeLayout, GridOriginFromMargin, LockQuickStyleSet, LockTheme, OMathLeftMargin, OMathRightMargin, PageSetup, ReadingLayoutSizeX, ReadingLayoutSizeY, ReadingModeLayoutFrozen, RemoveDocumentInformation, RemoveLockedStyles, RemovePersonalInformation, RemoveTheme, SaveAsQuickStyleSet, SaveFormat, SaveSubsetFonts, SetDefaultTableStyle, Styles, StyleSheets, StyleSortMethod, TrackFormatting, UpdateStyles and UpdateStylesOnOpen

ActiveTheme

Returns the name of the active theme plus the theme formatting options for the specified document.

The ActiveTheme property returns "none" if the document doesn't have an active theme. For an explanation of the value returned by this property, see the Name argument of the ApplyTheme method. The value returned by this property may not correspond to the theme's display name. To return a theme's display name, use the ActiveThemeDisplayName property.

Sub CheckTheme() 
 ActiveDocument.ApplyTheme "artsy 100" 
 MsgBox ActiveDocument.ActiveTheme 
End Sub

ActiveWritingStyle

Returns or sets the writing style for a specified language in the specified document.

The WritingStyleList property returns an array of the names of the available writing styles.

Syntax : expression.ActiveWritingStyle (LanguageID)

LanguageID: The language to set the writing style for in the specified document. Can be either a string or one of the following WdLanguageID constants. Some of the WdLanguageID constants may not be available to you, depending on the language support (U.S. English, for example) that you have selected or installed.

With ActiveDocument 
 .ActiveWritingStyle(wdFrench) = "Commercial" 
 .ActiveWritingStyle(wdGerman) = "Technisch/Wiss" 
 .ActiveWritingStyle(wdEnglishUS) = "Technical" 
End With

ApplyQuickStyleSet2

Applies the specified Quick Style set to the document.

Syntax : expression.ApplyQuickStyleSet2 (Style)

Style: Can be either a String that specifies the name of the set to use (corresponds to the name listed in the Style Set list) or a constant from the WdApplyQuickStyleSets enumeration.

ActiveDocument.ApplyQuickStyleSet2 Style:=

ApplyTheme

Applies a theme to an open document.

Syntax : expression.ApplyTheme (Name)

Name: The name of the theme plus any theme formatting options you want to apply. The format of this string is "themennn" where theme and nnn are defined as follows:

ActiveDocument.ApplyTheme "artsy 100"

AutoFormat

Automatically formats a document.

Use the Kind property to specify a document type.

ActiveDocument.AutoFormat

AutoFormatOverride

Returns or sets a Boolean that represents whether automatic formatting options override formatting restrictions in a document where formatting restrictions are in effect.

ActiveDocument.AutoFormatOverride = True

ClickAndTypeParagraphStyle

Returns or sets the default paragraph style applied to text by the Click and Type feature in the specified document.

To set the ClickAndTypeParagraphStyle property, specify either the local name of the style, an integer, or a WdBuiltinStyle constant, or an object that represents the style. For a list of the WdBuiltinStyle constants, consult the Microsoft Visual Basic Object Browser. If the InUse property for the specified style is set to False, an error occurs.

With ActiveDocument 
 x = "Plain Text" 
 If .Styles(x).InUse Then 
 .ClickAndTypeParagraphStyle = x 
 Else 
 MsgBox "Sorry, this style is not in use yet." 
 End If 
End With

CopyStylesFromTemplate

Copies styles from the specified template to a document.

When styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.

Syntax : expression.CopyStylesFromTemplate (Template)

Template: The template file name.

ActiveDocument.CopyStylesFromTemplate _ 
 Template:=ActiveDocument.AttachedTemplate.FullName

DefaultTableStyle

Returns a Variant that represents the table style that is applied to all newly created tables in a document.

Sub TableDefaultStyle() 
 With ActiveDocument 
 If .DefaultTableStyle = "Table Normal" Then 
 .SetDefaultTableStyle _ 
 Style:="TableStyle1", SetInTemplate:=True 
 End If 
 End With 
End Sub

DefaultTabStop

Returns or sets the interval (in points) between the default tab stops in the specified document.

ActiveDocument.DefaultTabStop = InchesToPoints(1)

DocumentTheme

Returns an OfficeTheme object that represents the Microsoft Office theme applied to a document.

Use the ApplyDocumentTheme method to apply an Office theme.

Dim oteDocumentTheme As Office.OfficeTheme
Set oteDocumentTheme = ActiveDocument.DocumentTheme

DoNotEmbedSystemFonts

True for Microsoft Word to not embed common system fonts.

Setting the Document property to False is useful if the user is on an East Asian system and wants to create a document that is readable by others who do not have fonts for that language on their system. For example, a user on a Japanese system could choose to embed the fonts in a document so that the Japanese document would be readable on all systems.

Sub EmbedFonts() 
 With ActiveDocument 
 If .EmbedTrueTypeFonts = False Then 
 .EmbedTrueTypeFonts = True 
 .DoNotEmbedSystemFonts = False 
 Else 
 .DoNotEmbedSystemFonts = False 
 End If 
 End With 
End Sub

EmbedTrueTypeFonts

True if Microsoft Word embeds TrueType fonts in a document when it is saved.

Embedding TrueType fonts allows others to view a document with the same fonts that were used to create it.

ActiveDocument.EmbedTrueTypeFonts = True 
ActiveDocument.Save

EnforceStyle

Returns or sets a Boolean that represents whether formatting restrictions are enforced in a protected document.

ActiveDocument.EnforceStyle = True

FormattingShowClear

True for Microsoft Word to show clear formatting in the Styles and Formatting task pane.

Sub ShowClearFormatting() 
 With ActiveDocument 
 .FormattingShowClear = False 
 .FormattingShowFilter = wdShowFilterFormattingInUse 
 .FormattingShowFont = True 
 .FormattingShowNumbering = True 
 .FormattingShowParagraph = True 
 End With 
End Sub

FormattingShowFont

True for Microsoft Word to display font formatting in the Styles and Formatting task pane.

Sub ShowClearFormatting() 
 With ActiveDocument 
 .FormattingShowClear = False 
 .FormattingShowFilter = wdShowFilterFormattingInUse 
 .FormattingShowFont = True 
 .FormattingShowNumbering = True 
 .FormattingShowParagraph = True 
 End With 
End Sub

FormattingShowNextLevel

Returns or sets a Boolean that represents whether Microsoft Word shows the next heading level when the previous heading level is used.

This property corresponds to the Show next heading when previous level is used check box in the Styles Gallery Options dialog box.

ActiveDocument.FormattingShowNextLevel = True

FormattingShowNumbering

True for Microsoft Word to display number formatting in the Styles and Formatting task pane.

Sub ShowClearFormatting() 
 With ActiveDocument 
 .FormattingShowClear = False 
 .FormattingShowFilter = wdShowFilterFormattingInUse 
 .FormattingShowFont = True 
 .FormattingShowNumbering = True 
 .FormattingShowParagraph = True 
 End With 
End Sub

FormattingShowParagraph

True for Microsoft Word to display paragraph formatting in the Styles and Formatting task pane.

Sub ShowClearFormatting() 
 With ActiveDocument 
 .FormattingShowClear = False 
 .FormattingShowFilter = wdShowFilterFormattingInUse 
 .FormattingShowFont = True 
 .FormattingShowNumbering = True 
 .FormattingShowParagraph = True 
 End With 
End Sub

FreezeLayout

In Web view, fixes the layout of the document as it currently appears so that line breaks remain fixed and ink annotations do not move when you resize the window.

ActiveDocument.FreezeLayout

GridOriginFromMargin

True if Microsoft Word starts the character grid from the upper-left corner of the page.

ActiveDocument.GridOriginFromMargin = True

LockQuickStyleSet

Returns or sets a Boolean that represents whether users can change which set of Quick Styles is being used.

ActiveDocument.LockQuickStyleSet = True

LockTheme

Returns or sets a Boolean that represents whether a user can change a document theme.

Use the ApplyDocumentTheme method to apply a Microsoft Office theme. Use the DocumentTheme property to return the Office theme that is applied to a document.

ActiveDocument.LockTheme = True

OMathLeftMargin

Returns or sets a Single that represents the left margin for equations.

ActiveDocument.OMathLeftMargin =

OMathRightMargin

Returns or sets a Single that represents the right margin for equations.

ActiveDocument.OMathRightMargin =

PageSetup

Returns a PageSetup object that is associated with the specified document.

ActiveDocument.PageSetup.RightMargin = InchesToPoints(1)

ReadingLayoutSizeX

Sets or returns a Long that represents the width of pages in a document when it is displayed in reading layout view and is frozen for entering handwritten markup.

After setting the ReadingLayoutSizeX and ReadingLayoutSizeY properties, use the ReadingModeLayoutFrozen property to display the page using the specified height and width. Use the ReadingLayout property to display a document in reading layout view.

ActiveWindow.View.ReadingLayout = True 
ActiveDocument.ReadingLayoutSizeX = 300 
ActiveDocument.ReadingLayoutSizeY = 300 
ActiveDocument.ReadingModeLayoutFrozen = True

ReadingLayoutSizeY

Sets or returns a Long that represents the height of pages in a document when it is displayed in reading layout view and is frozen for entering handwritten markup.

After setting the ReadingLayoutSizeX and ReadingLayoutSizeY properties, use the ReadingModeLayoutFrozen property to display the page using the specified height and width. Use the ReadingLayout property to display a document in reading layout view.

ActiveWindow.View.ReadingLayout = True 
ActiveDocument.ReadingLayoutSizeX = 300 
ActiveDocument.ReadingLayoutSizeY = 300 
ActiveDocument.ReadingModeLayoutFrozen = True

ReadingModeLayoutFrozen

Sets or returns a Boolean that represents whether pages displayed in reading layout view are frozen to a specified size for inserting handwritten markup into a document.

Use the ReadingLayoutSizeX and ReadingLayoutSizeY properties to specify the size of the pages displayed when the reading layout size is frozen for inserting handwritten markup into a document.

ActiveWindow.View.ReadingLayout = True 
ActiveDocument.ReadingLayoutSize 300, 300 
ActiveDocument.ReadingModeLayoutFrozen = True

RemoveDocumentInformation

Removes sensitive information, properties, comments, and other metadata from a document.

Syntax : expression.RemoveDocumentInformation (RemoveDocInfoType)

RemoveDocInfoType: Specifies what to remove.

ActiveDocument.RemoveDocumentInformation RemoveDocInfoType:=wdRDIAll

RemoveLockedStyles

Purges a document of locked styles when formatting restrictions have been applied in a document.

ActiveDocument.RemoveLockedStyles

RemovePersonalInformation

True if Microsoft Word removes all user information from comments, revisions, and the Properties dialog box upon saving a document.

Sub RemovePersonalInfo() 
 ActiveDocument.RemovePersonalInformation = True 
End Sub

RemoveTheme

Removes the active theme from the current document.

ActiveDocument.RemoveTheme

SaveAsQuickStyleSet

Saves the group of quick styles currently in use.

Syntax : expression.SaveAsQuickStyleSet (FileName)

FileName: The path and file name for the quick style set file.

Dim strFileName As String: strFileName =  
ActiveDocument.SaveAsQuickStyleSet FileName:=strFileName

SaveFormat

Returns the file format of the specified document or file converter.

The SaveFormat property will be a unique number that specifies an external file converter or a WdSaveFormat constant. Use the value of the SaveFormat property for the FileFormat argument of the SaveAs2 method to save a document in a file format for which there isn't a corresponding WdSaveFormat constant.

If ActiveDocument.SaveFormat = wdFormatRTF Then 
 ActiveDocument.SaveAs FileFormat:=wdFormatDocument 
End If

SaveSubsetFonts

True if Microsoft Word saves a subset of the embedded TrueType fonts with the document.

If fewer than 32 characters of a TrueType font are used in a document, Word embeds the subset (only the characters used) in the document. If more than 32 characters are used, Word embeds the entire font.

With Documents("MyDoc") 
 .EmbedTrueTypeFonts = True 
 .SaveSubsetFonts = True 
 .Save 
End With

SetDefaultTableStyle

Specifies the table style to use for newly created tables in a document.

Syntax : expression.SetDefaultTableStyle (Style, SetInTemplate)

Sub TableDefaultStyle() 
 With ActiveDocument 
 If .DefaultTableStyle = "Table Normal" Then 
 .SetDefaultTableStyle Style:="TableStyle1", _ 
 SetInTemplate:=True 
 End If 
 End With 
End Sub

Arguments

The following arguments are required:

Style (Style) - A string specifying the name of the style.

SetInTemplate (Boolean) - True to save the table style in the template attached to the document.

Styles

Returns a Styles collection for the specified document.

For information about returning a single member of a collection, see Returning an object from a collection.

For Each para In ActiveDocument.Paragraphs 
 If para.Range.Words(1).Text = "Chapter " Then 
 para.Style = ActiveDocument.Styles(wdStyleHeading1) 
 End If 
Next para

StyleSheets

Returns a StyleSheets collection that represents the Web style sheets attached to a document.

Sub Styshts() 
 ActiveDocument.StyleSheets.Add _ 
 FileName:="c:\Website.css", _ 
 Precedence:=wdStyleSheetPrecedenceHighest 
End Sub

StyleSortMethod

Returns or sets a WdStyleSort constant that represents the sort method to use when sorting styles in the Styles task pane.

Possible Values are wdStyleSortByBasedOn - Sorts styles based on the item indicated in the Sort Styles Based On option, wdStyleSortByFont - Sorts styles based on the name of the font used, wdStyleSortByName - Sorts styles alphabetically based on the name of the style, wdStyleSortByType - Sorts styles based on whether the style is a paragraph style or character style, wdStyleSortRecommended - Sorts styles based on whether they are recommended for use.
ActiveDocument.StyleSortMethod = wdStyleSortByBasedOn

TrackFormatting

Returns or sets a Boolean that represents whether to track formatting changes when change tracking is turned on.

ActiveDocument.TrackFormatting = True

UpdateStyles

Copies all styles from the attached template into the document, overwriting any existing styles in the document that have the same name.

For Each aDoc In Documents 
 aDoc.UpdateStyles 
 aDoc.Close SaveChanges:=wdSaveChanges 
Next aDoc

UpdateStylesOnOpen

True if the styles in the specified document are updated to match the styles in the attached template each time the document is opened.

For Each doc In Documents 
 doc.UpdateStylesOnOpen = True 
 doc.Close SaveChanges:=wdSaveChanges 
Next doc