View Single Post
 
Old 10-30-2022, 05:59 AM
BrianHoard BrianHoard is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

This example displays the numbers for all bookmarks in your document as a msgBox. Since it appears your numbers vary in size, I'm extending the range as long as their are numbers in it. In the code below, you can see the line where your bookmark value from the document is being stored as the var, bookmarkValue.

It was being stored in the previous example as "code", so as Italophile mentioned, you are already storing it as a variable.

Next question for you - What are you going to do with the variable once you have it?
Posting a sample Word document (not screen shots) with the actual bookmarks you're trying to work with, and details about your end goal would be helpful.

This is like a mystery that we're learning a little more with each iteration

Code:
Sub bookmarkValues()
    Dim rng As Range
    Dim bm As Bookmark
    Dim rng_expanded As Range
    Dim bookmarkValue As String
    
    For Each bm In ActiveDocument.Bookmarks
      Set rng = bm.Range
      If rng.Start = rng.End Then
        Set rng_expanded = rng
        rng_expanded.MoveEndWhile cset:="0123456789"
        
        ' Store bookmark document text as a variable
        bookmarkValue = rng_expanded.Text
        
        Call MsgBox(prompt:=("Bookmark value: " & bookmarkValue), buttons:=vbOKOnly)
      End If
    Next bm

End Sub
Reply With Quote