Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 10-30-2022, 04:19 AM
bugy bugy is offline Word - position document Windows 10 Word - position document Office 2010
Novice
Word - position document
 
Join Date: Jan 2019
Posts: 16
bugy is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
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 image of my bookmark
I have executed the code that you have sent me and it has not given any error.
Code:
Sub TestBookmark()
    Dim rng As Range
    Dim code As String
    If ActiveDocument.Bookmarks.Exists("CodiPacient") Then
        Set rng = ActiveDocument.Bookmarks("CodiPacient").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
Can I save the value of the bookmark in a variable?
thanks
Attached Images
File Type: jpg 30-10-2022_12-14-47.jpg (8.7 KB, 16 views)
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