Thread: [Solved] Select Text after Bookmark
View Single Post
 
Old 05-09-2017, 08:17 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
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

You are getting your range names and bookmark names mixed up and not achieving the intended aim. Use the following to fill the bookmarks
Code:
Public Sub FillBM(strBMName As String, strValue As String)
'Graham Mayor - http://www.gmayor.com
Dim oRng As Range
    With ActiveDocument
        On Error GoTo lbl_Exit
        Set oRng = .Bookmarks(strBMName).Range
        oRng.Text = strValue
        oRng.Bookmarks.Add strBMName
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
and call it with
Code:
FillBM "bmContact", StrTextContact
FillBM "bmCompany", StrTxtCompany
etc
If the named bookmarks or the strings don't exist the function does nothing, otherwise the values are written into the named bookmarks, and are replaced if you run the calling macro again with different values.
__________________
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