View Single Post
 
Old 02-10-2021, 11:23 PM
SamDsouza SamDsouza is offline Windows 10 Office 2013
Advanced Beginner
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

As I moved on

How can i get bookmark.name as returned value against that particular para. if Bookmark existed with the bookmark.name in a particular paragraph

I get error 5941" "the requested member of the collection does not exist. I've made a blunder. Shall appreciate your guidance in correcting and helping me to remove the error
Code:
Public Sub ListBasicReturnedObjects()

Dim wdActDoc As Document
Dim oBkMrk As Bookmark
Dim StrData As String, StrSty As String, Sty As Style
Dim StrStory As String
Dim i As Long
Dim strHeader As String
                                                  
Set wdActDoc = ActiveDocument
                                                    
strHeader = "Para No" & Space(5) & "Style" & Space(12) & "Alignment" & Space(2) & "Font Name" & Space(24) & "BookMark"

StrData = strHeader & vbCrLf

With wdActDoc
  For i = 1 To .Range.Paragraphs.Count
    With .Paragraphs(i)
          StrSty = .Style
          StrData = StrData & vbCr & Format(i, "#00#") & Space(8) & Mid(StrSty, 1, Len(StrSty))
                
       Set Sty = wdActDoc.Styles(StrSty)
             If Len(.Style) <= 11 Then
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name    '& & vbTab
              Else
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name
             End If
       
              
       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
  TextBox1.Text = TextBox1.Text & StrData

End With

End Sub
SamD
Reply With Quote