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…