View Single Post
 
Old 05-19-2021, 07:25 PM
gdsgssy gdsgssy is offline Windows 10 Office 2019
Novice
 
Join Date: May 2021
Posts: 2
gdsgssy is on a distinguished road
Default

Thank you for you suggestion. I have changed the code to add bookmarks into range instead of document. To keep it simple, I don't want to add the function inserting reference to heading outline number right now. Thank you again.
Code:
    Dim oldbm As Bookmark
    Dim bmi As Bookmark
    Dim bmShowHiddenOld As Boolean
    bmShowHiddenOld = rg.Bookmarks.ShowHidden
    
    'search for existing bookmark reference the same range
    rg.Bookmarks.ShowHidden = True
    For Each bmi In rg.Bookmarks
        If bmi.Range.IsEqual(rg) And bmi.Name Like BookmarkPrefix & "#*" Then
            Set oldbm = bmi
            Exit For
        End If
    Next bmi
    rg.Bookmarks.ShowHidden = bmShowHiddenOld
Reply With Quote