Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #12  
Old 10-30-2022, 05:59 AM
BrianHoard BrianHoard is offline Word - position document Windows 10 Word - position document 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word - position document Can I make Word remember the window size and position for each document? Jennifer Murphy Word 4 02-20-2023 06:36 PM
Changing Caption Position on Whole Document at once Alexandarale Word Tables 1 11-15-2020 06:56 PM
Word - position document Copy selected text from one document and paste to new document in same position on the page gasparik Word VBA 1 05-11-2020 05:41 AM
Starting a document, returning to last position glennnall Word 0 10-08-2017 10:09 AM
Word - position document VBA: how can I know the position on a document? tinfanide Excel Programming 3 02-27-2012 03:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft