View Single Post
 
Old 02-07-2019, 10:37 PM
aee74 aee74 is offline Windows 10 Office 2013
Novice
 
Join Date: Feb 2019
Posts: 5
aee74 is on a distinguished road
Default

[I will try this again tonight. But as I tried before nothing happens when I run the code. The code compiles without errors so I the code should be fine. The bookmarks are in the document and the autotext is saved in the template

QUOTE=gmayor;138239]The code I posted in the linked thread does work, provided you identify the autotext location correctly and apply the correct names for the autotext entry and the bookmark.



Code:
Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String)
'strBMName is the name of the bookmark to fill
'oTemplate is the template with the autotext - probably ActiveDocument.AttachedTemplate
'strAutotext is the name of the autotext entry
Dim oRng As Range
    On Error GoTo lbl_Exit
    With ActiveDocument
        Set oRng = .Bookmarks(strbmName).Range
        Set oRng = oTemplate.AutoTextEntries(strAutotext).Insert _
                   (Where:=oRng, RichText:=True)
        .Bookmarks.Add Name:=strbmName, Range:=oRng
    End With
lbl_Exit:
    Exit Sub
End Sub
[/QUOTE]
Reply With Quote