问题
I have a Word document containing a numbered list like this
- Item 1
- Item 2
- Item 3
The list style is "List Paragraph". Left indent of "List Paragraph" is 0.5". If we run the following code to reapply the style "List Paragraph", the left indent of the style is now 0.75"
Dim t As ListTemplate
Set t = ActiveDocument.Styles("List Paragraph").ListTemplate
t.ListLevels(1).ResetOnHigher = True
Selection.Range.ListFormat.ApplyListTemplate t, False, wdListApplyToWholeList
As a result, the list is shifted to the right 0.25". I'm wondering why the method ApplyListTemplate change the left indent of the style "List Paragraph".
Before and after applying the code, the description of the style are
"Indent:
Left: 0.5"
Hanging: 0.25", Numbered + Level: 1 + Numbering Style: 1, 2, 3, … + Start at: 1 + Alignment: Left + Aligned at: 0.75" + Indent at: 1", Style: Quick Style, Priority: 35
Based on: Text"
"Indent:
Left: 0.75"
Hanging: 0.25", Outline numbered + Level: 1 + Numbering Style: 1, 2, 3, … + Start at: 1 + Alignment: Left + Aligned at: 0.75" + Indent at: 1", Style: Quick Style, Priority: 35
Based on: Text"
I found the same behavior in both Office 2003 and 2010
回答1:
I can't test your exact code because I get a Run-time error 5941, which says "The requested member of the collection does not exist."
That being said, Word has a tendency (for me anyway) to "fix" the indent of a list whenever a change is made to its formatting. There's probably a setting to tell Word to stop "fixing" lists, but I suggest simply adding the following to the end of your code:
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0.75) ' Left indent
.RightIndent = InchesToPoints(0) ' Right indent
.FirstLineIndent = InchesToPoints(-0.25) ' First line indent
End With
That will give you a left indent of 0.5" and and a hanging indent of 0.25" (even though the numbers may look a little odd). You don't need the middle line that starts with .RightIndent =, but I thought I'd include it in the event you'd want to change that as well.
来源:https://stackoverflow.com/questions/6773341/word-style-is-changed-after-applying-applylisttemplate