VBA Code


Hidden Members

These are hidden in 365 because they want you to use BuildingBlockEntries instead

AttachedTemplate.AutoTextEntries 
NormalTemplate.AutoTextEntries

Selection.TypeText Text:="a1" 
Selection.Range.InsertAutoText

AutoText

AutoTextEntries.Insert

ActiveDocument.AttachedTemplate.AutoTextEntries("").Insert _ 
   Where:=Selection.Range, RichText:=True

Inserts the autotext called "MyAutoText" into the bookmark with the name "MyBookmark".

ActiveDocument.AttachedTemplate.AutoTextEntries("MyAutoText").Insert _ 
   Where:=ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Bookmarks("MyBookmark").Range, _
   RichText:=True

Content Controls


Word.wdContentControlType. 
objDocument.ContentControls
objRange.ContentControls

Public Sub ContentControls_ListAll() 
Dim objcontentcontrols As Word.ContentControls
Dim objcontentcontrol As Word.ContentControl
Dim icontrols As Integer

    Set objcontentcontrols = ActiveDocument.Range.ContentControls
    
    For icontrols = 1 To objcontentcontrols.Count
        Set objcontentcontrol = objcontentcontrols.Item(icontrols)
                
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlRichText) Then
            Debug.Print icontrols & " - wdContentControlRichText - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlText) Then
            Debug.Print icontrols & " - wdContentControlText - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlPicture) Then
            Debug.Print icontrols & " - wdContentControlPicture - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlComboBox) Then
            Debug.Print icontrols & " - wdContentControlComboBox - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlDropdownList) Then
            Debug.Print icontrols & " - wdContentControlDropdownList - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlDate) Then
            Debug.Print icontrols & " - wdContentControlDate - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlBuildingBlockGallery) Then
            Debug.Print icontrols & " - wdContentControlBuildingBlockGallery - " & objcontentcontrol.Tag
        End If
        If (objcontentcontrol.Type = WdContentControlType.wdContentControlGroup) Then
            Debug.Print icontrols & " - wdContentControlGroup - " & objcontentcontrol.Tag
        End If
    Next icontrols
    
End Sub


Public Sub CopyAcross() 
   Call CopyAutoTextViaNormalScratchpad("MyAutoText")
End Sub

Sub CopyAutoTextViaNormalScratchpad( _
         ByVal entryName As String)
         
Dim docSource As Document
Dim docDest As Document
Dim docScratch As Document
Dim rngScratch As Range
    
    On Error Resume Next
    Set docSource = Documents("Template1.dotm")
    Set docDest = Documents("Template2.dotm")
    On Error GoTo 0
    
    If docSource Is Nothing Or docDest Is Nothing Then
        MsgBox "Ensure both templates are open as files before running.", vbCritical
        Exit Sub
    End If
    
    Set docScratch = Documents.Add(Template:="Normal.dotm", Visible:=True)
    Set rngScratch = docScratch.Content
    
    On Error Resume Next
    docSource.AttachedTemplate.AutoTextEntries(entryName).Insert Where:=rngScratch, RichText:=True
    If Err.Number <> 0 Then
        MsgBox "Could not find the entry '" & entryName & "' in the source file structure.", vbExclamation
        docScratch.Close SaveChanges:=wdDoNotSaveChanges
        Exit Sub
    End If
    On Error GoTo 0
    
    rngScratch.End = docScratch.Content.End
    
' docDest.AttachedTemplate.AutoTextEntries.Add name:=entryName, Range:=rngScratch
    docDest.AttachedTemplate.BuildingBlockEntries.Add _
        Name:=entryName, _
        Type:=WdBuildingBlockTypes.wdTypeCustomAutoText, _
        Category:="General", _
        Range:=rngScratch
    
    docScratch.Close SaveChanges:=wdDoNotSaveChanges
    
    MsgBox "AutoText entry successfully migrated via a blank Normal template canvas!", vbInformation
End Sub

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev