• Attached Template AutoText Problem (VBA/Word/97)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Attached Template AutoText Problem (VBA/Word/97)

    Author
    Topic
    #382455

    I am having a problem with some code that was working and has stopped. Maybe I am missing something obvious but this is the scenario.

    MS Word 97 starts with a template XYZ.dot stored in C:Program FilesMicrosoft OfficeOfficeStartup folder. (It contains all code, AutoText, custom toolbars, etc.) Code is run from the custom toolbar buttons each creating a new document based on a relevant template stored in the C:Program FilesMicrosoft OfficeTemplates folder.

    The following code WAS working but some assigned keyboard shortcuts gave up and so to clean up the XYZ.dot template I recreated it and copied all the code, AutoText, custom toolbars, etc. using the Organizer faithfully copying all across to the new copy of XYZ.dot.

    An experienced user then noted that the keyboard shortcuts were not working. I deleted all four, recreated them and they worked, even though they appear to be exactly as they were. Now the following code is not working for adding some information to a Memo. It uses a bookmark (it exists in the copy of the Memo.dot) and an AutoText entry (from the globally loaded XYZ.dot).

    Public Sub MAIN()
        ActiveDocument.Bookmarks("res").Select
        ActiveDocument.AttachedTemplate = "C:Program FilesMicrosoft OfficeOfficeStartupXYZ.dot"
        ActiveDocument.AttachedTemplate.AutoTextEntries("response").Insert _
            where:=Selection.Range, RichText:=True
        ActiveDocument.Bookmarks("Start").Select
    End Sub

    This brings up the error ” Run-time error ‘438’ Object doesn’t support this method or property

    Any suggestions?

    Leigh

    Viewing 0 reply threads
    Author
    Replies
    • #648509

      Why is the add in also the attached template? Surely you only need it once and not twice.

      The error message appears to be saying that something is missing. Which line the error comes up on is the key. Try stepping through the macro to see which line is the stumbling block. The first line is looking for a bookmark, the second for an autotext entry and the third for another bookmark – one of these is missing.

      If you attach the XYZ.dot only to get at the autotext entry, you may prefer to get that from the template when it is an add in. This link will show you how.

      • #648682

        Thanks Andrew, your pointer to that post solved the problem. Following your suggestion, the code stopped when inserting the “response” AutoText entry although it was listed in the AutoText entries under the Tools | AutoCorrect… | AutoText listing. Strange!

        The two references in the code to AttachedTemplate were changed to the following line of code:

        Templates("C:Program FilesMicrosoft OfficeOfficeStartupXYZ.dot") _
                .AutoTextEntries("response").Insert Where:=Selection.Range, RichText:=True

        Problem solved. It seems that the original code did not specifically reference the XYZ.dot template when it looked like it was.

        • #648717

          I think the problem was because you had the template loaded twice – once as the attached template and once as an add-in. I am guessing that the add-in has taken precedence and Word won’t let you get at the attached template autotext as a result.

          To avoid the confusion don’t bother attaching the template unless you need it for other reasons in which case, don’t make the template an add-in.

    Viewing 0 reply threads
    Reply To: Attached Template AutoText Problem (VBA/Word/97)

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

    Your information: