Results 1 to 5 of 5

Thread: Word VBA efficiency (novice)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    You can insert more than one autotext entry into a content control, one after another, but you would need to modify the code to allow that e.g. the following will insert the

    Sub AutoTextToCC2(strCCName As String, oTemplate As Template, strAutotext As String)
        ' Graham Mayor - https://www.gmayor.com - Last updated - 10 Apr 2019
        ' strCCName is the ContentControl title
        ' oTemplate is the template with the autotext entry
        ' strAutotext is the name of the autotext entry
        Dim oCC As ContentControl
        Dim oRng As Range
        On Error GoTo lbl_Exit
        For Each oCC In ActiveDocument.ContentControls
            If oCC.TITLE = strCCName Then
                oCC.LockContentControl = True
                Set oRng = oCC.Range
                If oCC.ShowingPlaceholderText = False Then
                    oRng.Collapse 0
                End If
                oTemplate.AutoTextEntries(strAutotext).Insert Where:=oRng, RichText:=True
                Exit For
            End If
        Next oCC
        lbl_Exit:
        Exit Sub
    End Sub
    You can use macros to limit the length of the content of a control.
    Last edited by Aussiebear; 04-30-2025 at 01:10 AM.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •