none
AutoText Document Alphabetically RRS feed

  • Question

  • I am using the code below to create a document containing a list of AutoText, which works as is.  I would like for it to generate the list in alphabetical order.  Any suggestions?

    Public Sub CreateDocument()
     
      Dim docAutoText As Document
      Dim tplLocalTemplate As Template
      Dim sPath As String
      Dim atEntry As AutoTextEntry
      Dim rngRange As Range
      Const DASHED_LINE = _
        "-------------------------------------------------------------"
     
      On Error GoTo HandleError
      sPath = GetActivePath
     
      Set tplLocalTemplate = Templates(sPath & LOCAL_AT_NAME)
      Set docAutoText = New Word.Document
      docAutoText.Range(0, 0).Select
      For Each atEntry In tplLocalTemplate.AutoTextEntries
        With Selection
          .Font.Bold = True
          .Font.Size = 14
          .InsertAfter atEntry.Name & vbCrLf & vbCrLf
          .Collapse wdCollapseEnd
          .Font.Bold = False
          .Font.Size = 12
        End With
        atEntry.Insert Where:=Selection.Range, RichText:=True
        Selection.InsertAfter (vbCrLf & DASHED_LINE_ & vbCrLf)
        Selection.Collapse wdCollapseEnd
      Next atEntry
      docAutoText.Range(0, 0).Select
     
    ProcEnd:
      Exit Sub
     
    HandleError:
      Call LocalErrorMessage(Err.Number, Err.Description, "CreateDocument")
      Err.Clear
      Resume ProcEnd
     
    End Sub 'CreateDocument

    Friday, May 4, 2012 3:46 PM

Answers

All replies