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

    Autotext listing (W97, WinNT4)

    Another quick query ... I recently found some code that I was able to adapt to produce a list of all the autotext entries stored in the normal template, as follows:

    Sub AutoTexttList()
    Dim ATvar As AutoTextEntry
    Documents.add
    For Each ATvar In NormalTemplate.AutoTextEntries
    Selection.TypeText ATvar.name & vbCr & ATvar.Value & vbCr & "------------" & vbCr
    Next
    End Sub

    My question is this; the resulting list is fine, except that if the entry is more than a couple of lines long, it is truncated and the rest is not given. Is there a reason for this, and if so, is there a way to stop it? It's ruining my otherwise very useful macro!

    Many thanks in advance for your help!
    Beryl M


  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Autotext listing (W97, WinNT4)

    Hi Beryl,
    The Value property of an autotext entry only returns the first 255 characters at most (at least in OXP - may have been less before). Sadly, I don't offhand know of a way around that.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Autotext listing (W97, WinNT4)

    I take it the built-in "Print Autotext list" feature is not what you want?

    File>Print>Print What>AutoText entries
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Autotext listing (W97, WinNT4)

    Instead of
    Selection.TypeText ATvar.Value
    you can use
    ATvar.Insert Where:=Selection.Range, RichText:=True

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

  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: Autotext listing (W97, WinNT4)

    Rory - at least that explains what happened!
    Klaus - I made your suggested change and the macro does now give the whole content of the entry, although I had to fill in fields etc this time as if it were live, rather than just getting a list, and finally ...

    Kevin - <img src=/S/doh.gif border=0 alt=doh width=15 height=15> - it's a good thing someone around here knows what they're talking about, 'cos I obviously don't! I didn't even know that option was there, and actually it's precisely what I wanted! <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

    Many thanks, all!
    Beryl M


  6. #6
    Star Lounger
    Join Date
    Jun 2002
    Posts
    98
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Autotext listing (W97, WinNT4)

    We set up a macro that dumps out all the Autotext names and entries. By using a Style (GreenUglyCourier) for the Autotext name and no style for the actual Autotext content it's easy to separate the two while reviewing. We added an "Update Autotext" macro that lets the user make changes to the Autotext contents right in the doc and then click a button to update it. Update macro:

    1. Checks to see if you're on text that has style GreenUglyCourier (if not then quit w/msg)
    2. Selects and stores current line text (this is the name of the Autotext)
    3. Goto next line down, select down line by line until it hits a GreenUglyCourier style line.
    4. Store Selection as Autotext name.
    5. Move down a line to the next Autotext so user can click macro button again to update the next Autotext.

    This process makes it really easy for our end users to update a bunch of Autotexts. Two buttons:
    1. Deletes everything in the current doc and then types all Autotext names/contents
    2. Update currently highlighted Autotext.
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Autotext listing (W97, WinNT4)

    Could you explain what you mean by "By using a Style (GreenUglyCourier) for the Autotext name and no style for the actual Autotext content".

    I'm not sure what you mean by "using a style for the autotext name". How do you give the "name" a style?

    I think you are on to something here. I could use a solution like the one you're using. But first I need to "assign" a group of autotext entries to a specific style -- hopefully NOT manually. If you could explain, I'd appreciate it. Mean while, it's back to the search results page...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Star Lounger
    Join Date
    Jun 2002
    Posts
    98
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Autotext listing (W97, WinNT4)

    To create the body text of the template I use a macro (wish I had the source here at home to post for you) that basically does this:

    Deletes any pre-existing text in doc.
    Loops through all autotexts, typing first the name of the autotext using SPECIAL style, then back to Normal style, then dumps contents of Autotext.

    That creates a document filled with all your autotexts that easy to edit. Then the SECOND macro updates the actual Autotexts based on what you've got in the body. This macro does:

    Goto top
    START LOOPING:
    Select row (name of autotext and store to a variable)
    Go down a line and start selecting down one row at a time until you hit a row that has SPECIAL style applied. Then back up a row.
    Now you've got the updated (or not) text selected.
    Store it as an autotext using the name you stored to the variable.
    GOTO START LOOPING

    Hope that makes sense.
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

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

    Re: Autotext listing (W97, WinNT4)

    Hi Sister Dory, I know it's a long time since you wrote this note, but if you're still around this macro sounds absolutely perfect for what I want to do now - is there any chance of a copy of the code?

    I'd be really grateful!
    Beryl M


  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Autotext listing (W97, WinNT4)

    I'm not Sister Dory, but... for the middle steps of this macro ("Go down a line and start selecting down one row at a time until you hit a row that has SPECIAL style applied. Then back up a row."), you could call a procedure that extends the selection to contiguous paragraphs of the same style. Like so:

    <code>Sub SelectCurrentStyle()
    With Selection
    .Paragraphs(1).Range.Select
    Do
    If .Next.Style = .Paragraphs(.Paragraphs.Count).Style Then
    .MoveDown wdParagraph, 1, wdExtend
    Else
    Exit Do
    End If
    Loop
    End With
    End Sub</code>


    It occurs to me that there might be better "SelectCurrentStyle" procedures on the web, since this is a glaring omission among the .SelectCurrentAttribute methods available in Word 2003.

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

    Re: Autotext listing (W97, WinNT4)

    Sister Dory replied to my PM rather than to the thread so I said I would post her reply here - and here it is! Thanks, DoryO!
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    In your template, define a style called "AutoTextName" -- used to differentiate the Autotext name when it dumps out the listing.
    Mine is green, bold COURIER so it stands apart from the autotext content.

    Open a copy of the template and run the "dump" macro. This deletes everything in the document (just a copy so who cares) then dumps a listing of all the autotexts.
    Edit and update a single autotext by putting cursor on it and running the update macro.
    I created a commandbar with two buttons to run each of these macros and saved it to the template.
    So it's super easy to update the template once you have everything set up. Just open a copy, click Dump, edit, click Update, Save template.


    Sub DumpAutotexts()
    'Open a copy of the template, not the template itself
    'Make sure you have a style called "AutoTextName" defined in the template
    'This macro will delete the contents of the file and dump out
    'the autotexts from this template
    'Then you edit them and run the "UpdateThisAutotext" to change them.
    'Save the template when you close the doc

    Dim x As Integer
    If ActiveDocument.Name = ActiveDocument.AttachedTemplate.Name Then
    MsgBox "You can't run this macro on the Quote Template itself. " & Chr(13) & "Close this template and open the AutoTexts for Quotes.doc."
    GoTo Done
    End If

    ActiveDocument.Save

    x = MsgBox("Are you sure you want to delete all text and replace with list of current AutoTexts?", vbYesNo)
    If x = vbNo Then GoTo Done

    ActiveDocument.Range.WholeStory
    ActiveDocument.Range.Delete

    Selection.TypeText " ** BEGINNING OF AUTOTEXTS ** "
    Selection.Style = ActiveDocument.Styles("AutoTextName")
    Selection.TypeParagraph
    Selection.TypeParagraph

    For Each entry In ActiveDocument.AttachedTemplate.AutoTextEntries
    If Mid(entry.Name, 1, 2) = "Z-" Then GoTo LoopEnd
    Selection.TypeText entry.Name
    Selection.Style = ActiveDocument.Styles("AutoTextName")
    Selection.TypeParagraph
    entry.Insert Where:=Selection.Range, RichText:=True
    LoopEnd:
    Next entry

    Selection.TypeParagraph
    Selection.TypeText " ** END OF AUTOTEXTS ** "
    Selection.Style = ActiveDocument.Styles("AutoTextName")

    Done:
    End Sub

    Sub UpdateThisAutoText()

    If Selection.Style <> ActiveDocument.Styles("AutoTextName") Then
    MsgBox "Highlight a line where the style is AutoTextName (green)"
    GoTo Done
    End If

    'Go up until you reach an AutoTextName style
    While Selection.Paragraphs(Selection.Paragraphs.Count).S tyle <> "AutoTextName"
    Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
    Wend
    'copy the current line
    Selection.HomeKey
    Selection.EndKey Unit:=wdLine, Extend:=wdExtend
    AutoName = Trim(Selection.Text)
    'to beginning of next line
    Selection.MoveDown Unit:=wdParagraph, Count:=1
    'Selection.HomeKey Unit:=wdLine

    'Highlight all rows until another "AutoTextName" style is encountered
    While Selection.Paragraphs(Selection.Paragraphs.Count).S tyle <> "AutoTextName"
    Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    Wend
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.HomeKey Extend:=wdExtend
    ' Selection.MoveDown Unit:=wdLine, Count:=-1, Extend:=wdExtend

    'Update the Autotext
    ActiveDocument.AttachedTemplate.AutoTextEntries.Ad d Name:=AutoName, Range:=Selection.Range

    'back into position
    Selection.MoveRight Unit:=wdCharacter, Count:=1

    Done:
    End Sub

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Beryl M


Posting Permissions

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