VBA Code

Types of Views

Application.ActiveWindow.View.Type = wdViewType.wdNormalView 

Displays all non printing characters (hidden text, tab marks, space marks, paragraph marks)


Toggles the display of just headings or Headings and text

objView.ShowAllHeadings = True / False 

Toggles the display of square brackets around each bookmarks

objView.ShowBookmarks = True / False 


Displaying the Ruler

This is equivalent to (View > Ruler).
Returns or sets whether the ruler(s) is displayed in the active window (Print Layout).
ActiveWindow.DisplayRulers = True
If the view is Print Layout and the Display Rulers is true then the DisplayVerticalRulers determiens whether a vertical ruler will be displayed.

If Application.DisplayRulers = False Then 

End If

You cannot display a vertical ruler unless the horizontal ruler is displayed.

Move to a particular page

Selection.GoTo What:=wdGoToPage 

Document Map

This is the vertical area across the left edge of the window that displays an Outline of the document using heading styles
Determines if the document map is visible or not

Application.DocumentMap = True / False 

Returns or sets the width of the document map as a percentage of the width of the window.

Application.DocumentMapPercentWidth = 20 

Get the Column Number of the selection

This only works for selections, not for ranges.

With Dialogs(wdWordDialog.wdDialogFormatColumns) 
   Debug.Print . ColumnNo
End With

Selecting Pages

To select the page the cursor is in

Selection.GoTo What:=wdGoToBookmark, Name:="\page" 

Deleting Pages

'To set a range object to the page the range is currently in:
'Having previously set the MyRange variable to a range somewhere ...
'you can then operate on the page without selecting it, e.g.

Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page") 

'To set a range object to a particular page number:
'you can then operate on the page without selecting it, e.g.

Dim MyRange As Range 
Set MyRange = ActiveDocument.Range(0, 0)
Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:="4")
Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")

Inserting Pages

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext