View Single Post
 
Old 02-11-2021, 12:09 AM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Look at the 'logic' of what you're doing:
Code:
  For i = 1 To .Range.Paragraphs.Count
    With .Paragraphs(i)
...
       If wdActDoc.Bookmarks.Exists("mybookmark") = False Then
          StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name & ActiveDocument.Bookmarks(i).Name 'oBkMrk.Name
        End If
    End With
   Next
So, you're looking through paragraphs, via a counter designated 'i'. Every time you execute the loop, you test whether a bookmark named 'mybookmark' exists anywhere in the document. If not, you tell Word to return whatever 'ActiveDocument.Bookmarks(i).Name' is - again without regard to where that bookmark might be.

Note that you're not asking Word to tell you about a bookmark in 'wdActDoc' (which may no longer be the active document) and you're not even trying to establish that a bookmark with the same index (i) as the paragraph exists before trying to get its name.

Hardly surprising you're having problems.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote