View Single Post
 
Old 10-30-2022, 03:47 AM
Italophile Italophile is offline Windows 11 Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

When you next ask a question please include as much detail as possible. It is very hard to help someone when they haven't provided vital details, i.e. "I have a document with inserted bookmarks" and "The document is created by a VB6 program"

The attached screenshot shows the difference between a collapsed and enclosing bookmark, and how to show bookmarks in your document.

If you have no control over the document and you know that the code is never more than 4 characters you can edit your code as follows:
Code:
Sub TestBookmark()
    Dim rng As Range
    Dim code As String
    If ActiveDocument.Bookmarks.Exists("code") Then
        Set rng = ActiveDocument.Bookmarks("code").Range
        If rng.Start = rng.End Then
            rng.MoveEnd wdCharacter, 4
            code = rng.Text
            Debug.Print code
        Else
            code = rng.Text
            Debug.Print code
        End If
    Else
        MsgBox "This bookmark doesn't exist" & vbCr & "code"
    End If
End Sub
Attached Images
File Type: png Advanced Options.png (46.3 KB, 15 views)
File Type: png Screenshot_20221030_104105.png (5.6 KB, 15 views)
Reply With Quote