Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    List Template (Word XP)

    I have created a macro to create a list template with the help of many of you! I have run into one problem which I've tried to 'logically' figure out but with no success. Initially, the macro for each 'scheme' (list number template) which I create clears the list gallery, then begins looking for the first style in that particular list, if it exists then it simply reattaches the list template; however, if it does not exist it goes to the error handler area to begin creating all the styles then attaches the list template. The code is as follows:

    For Each listgal In ListGalleries
    For i = 1 To 7
    listgal.Reset (i)
    Next i
    Next listgal

    ' Check for style named "ArticleN2 L1"
    ' If not there, goes to error handler

    Dim StyleExist As Object
    Dim S As Integer
    Dim Style2
    On Error GoTo StyleNotThere

    Set StyleExist = ActiveDocument.Styles("ArticleN1 L1")
    If StyleExist.NameLocal = ("ArticleN1 L1") Then

    ' Check for List Template in document - if there, uses current,
    ' if not, creates

    Dim OLstTemp As ListTemplate, TemplateFound As Boolean

    For Each OLstTemp In ActiveDocument.ListTemplates
    If OLstTemp.Name = "ArticleN1" Then
    TemplateFound = True
    Exit For
    End If
    Next OLstTemp

    If TemplateFound Then
    Set OLstTemp = ActiveDocument.ListTemplates("ArticleN1")
    Else
    Set OLstTemp = ActiveDocument.ListTemplates.Add(OutlineNumbered:= True, _
    Name:="ArticleN1")
    End If

    The current problem which I'm trying to figure out is that all the styles are based on a style which I created called BodyText (not Word's built-in Body Text). This macro works fine for all new documents; however, if an older document is opened and the user wants the numbering applied it dies with error 5834 - not finding the based style BodyText. What I need is for it to look for the BodyText style first and if it does not exist then create, then look for the next style, e.g., ArticleNo1 L1 and continue the remainder of the macro. I tried to use another error handler after the first error handler... failed... tried to call another procedure upon error... failed... tried more if statements after error handler... failed??????????????

    I thought about changing the ArticleNo. L1 error handler to BodyText; however, a user may select more than one 'scheme' (list template) in their document. Logically, I'm fried like an egg... any ideas? Thanx for your help in advance...

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

    Re: List Template (Word XP)

    I don't know if this will help, but you can copy the styles from your latest, greatest template into any old legacy docs with this command:

    ActiveDocument.CopyStylesFromTemplate Template:="C:TemplatesNewTemplate.dot"
    __________________________________________________ ____
    <img src=/S/nun.gif border=0 alt=nun width=20 height=20> Sister Dory
    Our Lady of Perpetual Help, Holstein Falls, Wisconsin, USA

  3. #3
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Template (Word XP)

    Thanx for the suggestion... I have already created another macro to update all the styles based on the normal (which will include BodyText); however, I wanted to include just the BodyText style instead of getting all the styles in the current document. I may have to resolve to your suggestion if I receive no others though... thanx again Sis!

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: List Template (Word XP)

    Another workaround which may work to bring just a single style from one document into another, is to reproduce in code the following steps in Word:

    - Open a document which contains a paragraph with the style BodyText applied to it (could be just an empty paragraph).
    - Copy the paragraph.
    - Close the document without saving.
    - Go to your target document and paste the copied paragraph.
    - Then immediately delete the paragraph.

    I haven't used this trick in years (and haven't tested it now) but it used to the case that simply copying a paragraph with a new style into a document, and immediately deleting it, sufficed to make that new style a part of the target document. (Which is why it's important to use Paste Special > Unformatted Text when pasting content from one type of document into another.)

    You could also look into code using the Organizer object to copy a single style from one document to another - probably a cleaner approach than the above.

    Gary

  5. #5
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: List Template (Word XP)

    Hi Trish... The responses in this thread suggesting you copy the style into the document are probably pretty sound. However, knowing what the progression is for this whole process would be helpful. For example, if there's a possibility that someone with a newer document has somehow edited BodyText in their document would lessen the value of automatically copying the style over it.

    If, on the other hand, your company has strict rules about formatting and no one should be messing with BodyText, well...

    In regard to your original question, and off the top of my head, I suggest that your macro check for the existence of the BodyText style first and if it doesn't exist, create it. You seemed to say this had occurred to you, but you followed it with "however, a user may select more than one 'scheme' (list template) in their document" -- how does this impact searching for your BodyText style?

    I *think* what you want to do can be done (that is, if I'm clear on what you want to do), but you may need to build a couple more modules to call in order to separate your error handling code.

    Kim

  6. #6
    3 Star Lounger
    Join Date
    Apr 2003
    Location
    Calgary, Alberta
    Posts
    208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List Template (Word XP)

    Thanx for getting back to me Kim... Hans figured it out for me this morning. It is posted here <post#=256901>post 256901</post#>
    I have also included his note to me here in case anyone is interested. Sorry about the confusion in my note, I meant to say that since a user may select more than one 'scheme' I needed code to check for BodyText first instead of failing when another scheme could be selected. Hans' code below did the trick to add another error handler! Thanx again for replying Kim... have a great day... <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

    You could insert code after resetting the listgalleries:

    ' Check for style named "BodyText"
    ' If not there, create it

    Dim StyleBodyText As Style
    On Error Resume Next
    Set StyleBodyText = ActiveDocument.Styles("BodyText")
    If Err <> 0 Then
    Err.Clear
    Set StyleBodyText = ActiveDocument.Styles.Add("BodyText")
    With StyleBodyText
    ' Set style properties here, for example:
    .Font.Name = "Arial"
    End With
    End If

    Regards,
    Hans

  7. #7
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: List Template (Word XP)

    Most excellent!

    And thanks for posting his reply.

    K

Posting Permissions

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