View Single Post
 
Old 07-27-2023, 02:08 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Your code didn't work because it returns the ListValue and not the ListString. My fault; I should have checked instead of assuming that it worked before. Try the following instead
Code:
Sub AddBookmarksWithCharsOfParagraphNumber()
Dim para As Paragraph
Dim bookmarkName As String
Dim paragraphNum As String
            
    ' Loop through each paragraph in the active document
    For Each para In ActiveDocument.Paragraphs
        ' Check if the paragraph is a list paragraph
        If para.Range.ListFormat.ListType <> WdListType.wdListNoNumbering Then
            ' Get the paragraph number and convert it to a string
            paragraphNum = para.Range.ListFormat.ListString
           
            ' Generate a bookmark name with the first four characters of the paragraph number
            bookmarkName = "Bookmark_" & paragraphNum
            'paragraphNumStr = Left(paragraphNumStr, InStr(1, paragraphNumStr, Chr(32)))
            bookmarkName = "Bookmark_" & Trim(Replace(paragraphNum, ".", "_"))
            ' Add a bookmark to the paragraph
            ActiveDocument.Bookmarks.Add bookmarkName, para.Range
        End If
    Next para
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote