Using a checkbox to insert building blocks at bookmarks
I have a template that opens with a Userform from which the user can select up to 11 options (checkboxes) to enable blocks of text (BuildingBlocks) to be included in the final document at a bookmark. So far I have been unable to get his to work successfully for even one of the checkboxes, and am now trying the below code that I adapted from another post on this forum (with thanks to Graham Mayor). I am getting the Compile error - User-defined type not defined with the code below at line Sub AutoTextToBM . Can anybody help with this please, I have also tried using the template name instead of ActiveDocument.AttachedTemplate but that just throws up other errors?
Option Explicit
Private Sub CommandButton1_Click()
If CheckBox1.Value Then
AutoTextToBM "bmPlace", "ActiveDocument.AttachedTemplate", "BB_PWC"
End If
End Sub
Sub AutoTextToBM(bmPlace As String, oTemplate As ActiveDocument.AttachedTemplate, BB_PWC As String)'Graham Mayor - - Last updated - 17 Jul 2018
'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(bmPlace).Range
Set oRng = oTemplate.AutoTextEntries(BB_PWC).Insert _
(Where:=oRng, RichText:=True)
.Bookmarks.Add Name:=bmPlace, Range:=oRng
End With
lbl_Exit:
Exit Sub
End Sub