I am trying to apply a ListTemplate to a style. The code runs without error, but there is no change made to the document. Here are the details:
I have a UserForm that creates multiple documents and places them in a common project folder. The code creates a new document for each chapter and appendix of the document. The number of chapters and appendices is variable.
In my code (see excerpt below), I try to link the style "Chapter Heading 1" to a custom ListTemplate named "ltChapterOutline". I adjust the StartAt property, as well as the NumberFormat and NumberStyle (for appendices only). But when I open the newly created documents, each one is numbered as Chapter 1.
I have troubleshot this by stepping through the code on a dummy document, and it works fine. But when I run it from the UserForm, it fails to make the changes. Here is my code:
I realize the following two of the lines of code are redundant:
I have tried it both ways, but neither way seems to work.
Any ideas? I've been butting heads with this problem for three days now.
[purple]— Artificial intelligence is no match for natural stupidity.[/purple]
I have a UserForm that creates multiple documents and places them in a common project folder. The code creates a new document for each chapter and appendix of the document. The number of chapters and appendices is variable.
In my code (see excerpt below), I try to link the style "Chapter Heading 1" to a custom ListTemplate named "ltChapterOutline". I adjust the StartAt property, as well as the NumberFormat and NumberStyle (for appendices only). But when I open the newly created documents, each one is numbered as Chapter 1.
I have troubleshot this by stepping through the code on a dummy document, and it works fine. But when I run it from the UserForm, it fails to make the changes. Here is my code:
Code:
' Set m_Doc to newly created document and open it.
Set m_Doc = Documents.Open(FileName:=m_strFileLocation & strDocumentName, _
AddToRecentFiles:=False, Visible:=False)
With m_Doc
' Set values for CustomDocumentProperties.
.CustomDocumentProperties("ProjectName").Value = m_strProject
.CustomDocumentProperties(strDocType & "Name").Value = g_strAryPlanner(2, intEntry)
.CustomDocumentProperties(strDocType & "Number").Value = m_intChapter
' Set template.
.UpdateStylesOnOpen = True
.AttachedTemplate = Left(ThisDocument.Path, Len(ThisDocument.Path) - 5) _
& "\Styles\StyleTemplates\" & Me.lblStyleTemplate
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
' Set chapter number for Chapter Outline 1 style.
With .ListTemplates("ltChapterOutline").ListLevels(1)
If strDocType = "Appendix" Then
.NumberFormat = "Appendix %1:"
.NumberStyle = wdListNumberStyleUppercaseLetter
End If
.StartAt = m_intChapter
.LinkedStyle = "Chapter Outline 1"
End With
.Styles("Chapter Outline 1").LinkToListTemplate .ListTemplates("ltChapterOutline"), 1
End With ' m_Doc
I realize the following two of the lines of code are redundant:
Code:
.LinkedStyle = "Chapter Outline 1"
Code:
.Styles("Chapter Outline 1").LinkToListTemplate .ListTemplates("ltChapterOutline"), 1
Any ideas? I've been butting heads with this problem for three days now.
[purple]— Artificial intelligence is no match for natural stupidity.[/purple]