Option Explicit

Sub CreateAutoTextWithoutInsertingContentInDocument()

    'Macro created 2008 by Lene Fredborg, DocTools - www.thedoctools.com
    'The macro illustrates how you can create an AutoText
    'without first inserting the contents in a document
    'You may need to include error handling
    '=========================
    
    Dim oAutoText As AutoTextEntry
  
   'Create an AutoText with the current selection as the content
    'You could instead use any range from the document
    Set oAutoText = Templates(ActiveDocument.AttachedTemplate).AutoTextEntries _
        .Add(Name:="MyName", Range:=Selection.Range)

    'Now replace the content of the AutoText with the desired value
    oAutoText.Value = "ThisIsMyNewValue"
        
    'Clean up
    Set oAutoText = Nothing

End Sub

Sub EditExistingAutoTextsWithoutInsertingContentInDocument()
    
    'Macro created 2008 by Lene Fredborg, DocTools - www.thedoctools.com
    'The macro illustrates how you can replace a string in existing AutoTexts
    'without first inserting the AutoTexts
    'You may need to include error handling
    '=========================
    
    Dim oAutoText As AutoTextEntry
    Dim oTemplate As Template
    Dim strOld As String
    Dim strNew As String
    
    'Define the string to be replaced - change to the desired value
    strOld = "abc"
    'Define the replacement string - change to the desired value
    strNew = "12345"
    
    'Make sure to identify the correct template - here the attached template
    Set oTemplate = ActiveDocument.AttachedTemplate
    
    'Iterate through all AutoTexts in oTemplate and replace strings
    
    For Each oAutoText In oTemplate.AutoTextEntries
        oAutoText.Value = Replace(oAutoText.Value, strOld, strNew)
    Next oAutoText

    'Clean up
    Set oTemplate = Nothing

End Sub