none
List all Autotext Entries within the Autotext.dot file RRS feed

  • Question

  • I am looking for some VBA code that will insert all autotext entries that are held within the Autotext.dot file.

    We had Word 2010, where we saved all autotext into an "Autotext.dot" file.  The Normal.dotm file read from the Autotext.dot file for our autotext.  We have upgraded to Word 2016 and our templates still reference Autotext.dot as the template location of the autotext.

    I am wanting to list all of the autotext entries that we have, without having to add each one individually (i.e. Click 'Insert > Quick Parts > Building Block Organiser' and selecting each one.

    I would like some VBA code that I can add to a blank document and run to list all autotext that is saved within the Autotext.dot template.  The gallery is "Autotext" and the category is "General".

    Monday, July 17, 2017 1:46 AM

All replies

  • Hello,

    You could refer to the code below which could list all autotext in the Normal template.

    Sub ListBuildingBlocks()
    Dim tem As Template
    Set tem = Templates("Normal.dotm") 'Template Normal.dotm / yours may be "Autotext.dot"
    Dim cat As Category
    Dim bbt As BuildingBlockType
    Dim bb As BuildingBlock
    Set bbt = tem.BuildingBlockTypes(wdTypeAutoText) 'Gallery Autotext
    Set cat = bbt.Categories("General") 
    For i = 1 To cat.BuildingBlocks.Count
    Set bb = cat.BuildingBlocks.Item(i)
    Selection.TypeText "BuildingBlock " & bb.Name & vbCrLf
    Selection.TypeText vbTab & "Value " & bb.Value & vbCrLf
    Next i
    End Sub

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 18, 2017 3:20 AM
    Moderator
  • Thanks Celeste. 

    I keep getting a "Run-time error '5941' The requested member of the collection does not exist" on the line: 

          Set tem = Templates("Normal.dotx") 'Template Normal.dotm / yours may be "Autotext.dot"

    I have tried changing the above line to "Autotext.dot" but still get the same error.

    We have our "own" global template, which is saved in C:\Users\username\AppData\Roaming\Microsoft\Templates called "Normal.dotm".  There is no "Normal.dotx" in the location. 

    Somehow the "Normal.dotm" connects to the Autotext.dot file that is saved in another location (Q:\TEMPLATES\Microsoft Templates\Autotext.dot) - plus note that this location is now read-only.

    I'm not sure how to change your code so that it looks at the Autotext.dot template.

    When I change your code to "Normal.dotm", it does not list any of the custom autotext.  It lists the two autotext > general (gallery and category) that is within the "Normal.dotm" Template (which is my name and initials).

    Could it be because the Q:\TEMPLATES\Microsoft Templates\ location is now read-only?

    Tuesday, July 18, 2017 3:54 AM
  • Hello,

    Please go to Insert -> Quick Parts -> Building Blocks Organizer to check which Template your autotext filed belong to. Then use the name in line Templates("Normal.dotx")

    If you still get the error, you could try to change the location of Autotext.dot.

    And please share detail steps how you make "Normal.dotm" connect to the Autotext.dot file. I could follow your steps to reproduce the issue.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 20, 2017 4:30 AM
    Moderator