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

Quote:
Originally Posted by Guessed View Post
You have posted a sub with input variables which means this macro can't be run directly, it has to be passed some extra information in order to run). The sub also needs modification in order to use the variables that it expects to be passed in. To run it, you need a separate subroutine which passes in the variables and also to fix the function. Try
Code:
Sub Test_AutoTextToBM()
  AutoTextToBM strbmName:="bm1", oTemplate:=ActiveDocument.AttachedTemplate, strAutotext:="tekstbm1"
End Sub

Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String)
  'If CheckBox1 = True Then
  Dim oRng As Range
  On Error GoTo lbl_Exit    'will avoid errors if bookmark doesn't exist or AT doesn't exist in attached template
  Set oRng = ActiveDocument.Bookmarks(strbmName).Range
  Set oRng = oTemplate.AutoTextEntries(strAutotext).Insert(Where:=oRng, RichText:=True)
  ActiveDocument.Bookmarks.Add Name:=strbmName, Range:=oRng
lbl_Exit:
  Exit Sub
  'End If
End Sub

It works. Great. Thanks
Reply With Quote