• Autotext entries lose styles/numbering (Word 97/VBA)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Autotext entries lose styles/numbering (Word 97/VBA)

    Author
    Topic
    #359562

    I posted this question under the Word board, but thought I’d better post it under VB too. I am inserting autotext entries via a VBA routine in Word. The paragraphs contain the appropriate styles and numbering (Heading 1, Heading 2), and when I defined the autotext entries, I was sure to include the paragraph marker. However, when the document assembles at the end of the routine, the entire document is body text style. When inserted manually, the autotext entries are formatted fine. I don’t want to have to insert each paragraph separately via VB and then apply the appropriate style. Any suggestions from the experts?

    Viewing 0 reply threads
    Author
    Replies
    • #539231

      Post your code, specifically the line that inserts the autotext. I’m wondering if you are using the Richtext:= true argument.

      • #539234

        Hi Kev!

        Here’s a bit of it:

        ‘Yes Director – Yes Plan
        If frmAuditLtrStandard.CheckBox8 = True Then
        If frmAuditLtrStandard.CheckBox1 = True Then
        ActiveDocument.Variables.Add Name:=”AttorneyName”, Value:=frmAuditLtrStandard.TextBox31.Text
        ActiveDocument.Variables.Add Name:=”FiscalYear”, Value:=frmAuditLtrStandard.TextBox30.Text
        If frmAuditLtrStandard.OptionButton1 = True Then
        ActiveDocument.Variables.Add Name:=”AttorneyCapacity”, Value:=”Trustee”
        ElseIf frmAuditLtrStandard.OptionButton2 = True Then
        ActiveDocument.Variables.Add Name:=”AttorneyCapacity”, Value:=”Director”
        End If
        ActiveDocument.AttachedTemplate.AutoTextEntries(“Option11″).Insert _
        Where:=Selection.Range
        ‘Yes Director – No Plan
        ElseIf frmAuditLtrStandard.CheckBox8 = True Then
        If frmAuditLtrStandard.CheckBox1 = False Then
        ActiveDocument.Variables.Add Name:=”AttorneyName”, Value:=frmAuditLtrStandard.TextBox31.Text
        ActiveDocument.Variables.Add Name:=”FiscalYear”, Value:=frmAuditLtrStandard.TextBox30.Text
        If frmAuditLtrStandard.OptionButton1 = True Then
        ActiveDocument.Variables.Add Name:=”AttorneyCapacity”, Value:=”Trustee”
        ElseIf frmAuditLtrStandard.OptionButton2 = True Then
        ActiveDocument.Variables.Add Name:=”AttorneyCapacity”, Value:=”Director”
        End If
        ActiveDocument.AttachedTemplate.AutoTextEntries(“Option11A”).Insert _
        Where:=Selection.Range
        End If
        End If
        End If

        This is SO VEXING!!!! Thanks for any insight you can give me.

        • #539236

          Add Richtext:=true

          to this line:

          ActiveDocument.AttachedTemplate.AutoTextEntries(“Option11A”).Insert _
          Where:=Selection.Range, Richtext:=True

          From the Help:
          “RichText Optional Variant. True to insert the AutoText entry with its original formatting.”

          • #539246

            You are WONDERFUL Kevin! Thank you! That works. I looked under Help but richtext is not listed… I’m only using VBA — why wouldn’t it be listed in help though? Thanks again – you’re a lifesaver! cheers

    Viewing 0 reply threads
    Reply To: Autotext entries lose styles/numbering (Word 97/VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: