View Single Post
 
Old 02-09-2019, 08:04 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote