banner for Ms Access Gurus

Toggle Bookmark Display in Word Documents using VBA

Show or not show bookmark indicators in Word documents from Word, Access, or another VBA application.

use VBA to Write results of an Access Query To Word Bookmark

Quick Jump

Goto the Very Top  


Download

Download zipped BAS file with module that you can import into Word and/or any VBA application mod_aWord_BookmarksShowNotshow_s4p__BAS.zip

If you have trouble with the downloaded file, remember to unblock the original ZIP file, (aka remove Mark of the Web), BEFORE extracting file(s). Here are steps to do that: https://msaccessgurus.com/MOTW_Unblock.htm

Goto Top  

VBA

Standard module

'*************** Code Start *****************************************************
' module name: mod_aWord_BookmarksShowNotshow_s4p
'-------------------------------------------------------------------------------
' Purpose  : VBA to show or hide bookmarks in the Word document
'              run from Word or use automation
' Author   : crystal (strive4peace)
' This code: https://msaccessgurus.com/VBA/aWord_BookmarksShowNotshow.htm
' LICENSE  :
'   You may freely use and share this code, but not sell it.
'   Keep attribution. Use at your own risk.
'-------------------------------------------------------------------------------

Sub aWord_BookmarksShowNotshow_s4p() 
'240821 strive4peace
' toggle bookmark display in Word document
' run from Word or use automation from Access, Excel, or another VBA application

   'CLICK HERE
   'Press F5 to run

   Dim oWord As Object  'Word.Application
   
   'Initialize Word
   On Error Resume Next 
   Set oWord = GetObject(, "Word.Application") 
   On Error GoTo Proc_Err 
   
   If oWord Is Nothing Then 
      'do nothing
      MsgBox  "Word isn't open",, "Can't get Word Object"
      Exit Sub 
   End If 
   
   With oWord.ActiveWindow.View 
      .ShowBookmarks = Not .ShowBookmarks 
   End With 
   
Proc_Exit: 
   On Error Resume Next 
   Set oWord = Nothing 
   On Error GoTo 0 
   Exit Sub 
  
Proc_Err: 
   MsgBox Err.Description _ 
       ,, "ERROR " & Err.Number _ 
        &  "   aWord_BookmarksShowNotshow_s4p"

   Resume Proc_Exit 
   Resume 
End Sub 
'*************** Code End ******************************************************
' Code was generated with colors using the free Color Code add-in for Access

Goto Top  

Reference

Microsoft Learn

Help: View object (Word)

Help: View.ShowBookmarks property (Word)

Goto Top  

Manual Steps

To show or hide bookmark indicators from Word Options: Advanced, Show document content, check or uncheck 'Show bookmarks'

Show bookmarks in Word Options

To insert a Bookmark, from the ribbon:

  1. Insert
  2. Bookmark (Links group)
  3. enter Bookmark name, MyBookmark in this example
  4. click Add

Word How to Insert Bookmark

Bookmark names in Word:

Goto Top  

Backstory

When you have bookmarks in a Word document, it's nice to quickly show or hide the indicators (Word calls them annotations).

In Word, you can add this code to your Normal template so you can run it anytime you're in Word. It also works from another application such as Access or Excel. Late binding is used so no need to reference the Microsoft Word #.# Object Library

Goto Top  

Share with others

Here's the link for this page in case you want to copy it and share it with someone:

https://msaccessgurus.com/VBA/aWord_BookmarksShowNotshow.htm

or in old browsers:
http://www.msaccessgurus.com/VBA/aWord_BookmarksShowNotshow.htm

Goto Top  

the simplest way is best, but usually the hardest to see ~ crystal

Show your appreciation

thank you

Goto Top