Results 1 to 7 of 7
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Recorded Macros don't work? (Word VBA)

    If you want to insert autotext into a document based on Beryl.dot, you can change NormalTemplate to ActiveDocument.AttachedTemplate

    If Beryl.dot is a global template (aka add-in), you can use

    Dim tpl As Template
    For Each tpl In Templates
    If tpl.Name = "Beryl.dot" Then
    tpl.AutoTextEntries("SpecTop").Insert Where:=Selection.Range, RichText:=True
    Exit For
    End If
    Next tpl

  2. #2
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Recorded Macros don't work? (Word VBA)

    I just recorded a macro to paste the contents of an existing Autotext entry called SpecTop from a specific template called beryl.dot into the active document, and the relevant line recorded as follows:

    NormalTemplate.AutoTextEntries("SpecTop").Insert Where:=Selection.Range, RichText:=True

    However, as soon as I tried to run the macro immediately afterwards (without touching anything, opening/closing anything or even moving the cursor), it fell over, saying the requested member of the collection didn't exist.

    Which is probably true enough, the autotext entry was in beryl.dot, not the normal template, but why did it record it as being in the normal template, and how can I tell it to look in the right place?!!

    [Edited to add: the macro was recorded into beryl.dot, if that makes a difference!

    I is confuggulated!! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>
    Beryl M


  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Recorded Macros don't work? (Word VBA)

    Thanks, Hans, I was trying to work out to tell it that the template was beryl.dot, but I got as far as

    application.templates("Beryl").autotextentries ...

    which didn't work and I couldn't work out how to go on from there!

    It is a global template when in use, and since the macro is recorded into beryl.dot it is guaranteed to be available when it's run!

    Many thanks again
    Beryl
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Recorded Macros don't work? (Word VBA)

    For some reason, Templates("Beryl.dot") doesn't work, so you have to loop through the Templates collection until you find the one named Beryl.dot.
    This is strange, because in most situations you can refer to a member of a collection by its name, e.g. Documents("Letter.doc"), or ActiveDocument.Styles("Heading 1"). I have no idea why that doesn't work for templates, it's frustrasting...

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Recorded Macros don't work? (Word VBA)

    Well, I'm glad to know it wasn't just me and that I was trying to do it in what *should* have been the correct way, anyway!

    Thanks again, Hans!
    Beryl M


  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recorded Macros don't work? (Word VBA)

    In Word2000 the loop runs well.
    The Normal.dot lines function as we would expect.
    The last two lines fail (Run-time error '5491')for my global add-in.

    <pre>Sub test()
    '''
    Dim tmp As Template
    For Each tmp In Application.Templates
    Debug.Print tmp.FullName ' succeeds
    Next tmp
    '''
    Debug.Print Application.Templates("normal.dot").FullName ' succeeds
    Debug.Print Application.Templates("Normal.dot").FullName ' succeeds
    Debug.Print Application.Templates("UW.dot").FullName ' fails '5941'
    Debug.Print Application.Templates("uw.dot").FullName ' fails '5941'
    End Sub</pre>


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Recorded Macros don't work? (Word VBA)

    Yep, it fails for global templates / add-ins.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •