应用 ApplyListTemplate 后更改 Word 样式 [英] Word style is changed after applying ApplyListTemplate

查看:57
本文介绍了应用 ApplyListTemplate 后更改 Word 样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Word 文档,其中包含一个这样的编号列表

I have a Word document containing a numbered list like this

  1. 项目 1
  2. 项目 2
  3. 第 3 项

列表样式为列表段落".列表段落"的左缩进为 0.5".如果我们运行以下代码重新应用样式列表段落",则样式的左缩进现在为 0.75"

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

结果,列表向右移动了 0.25".我想知道为什么 ApplyListTemplate 方法会更改样式列表段落"的左缩进.

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"

我在 Office 2003 和 2010 中发现相同的行为

I found the same behavior in both Office 2003 and 2010

推荐答案

我无法测试您的确切代码,因为我收到运行时错误 5941,其中显示请求的集合成员不存在."

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."

话虽如此,只要对列表的格式进行更改,Word 就会倾向于(无论如何对我来说)修复"列表的缩进.可能有一个设置告诉 Word 停止修复"列表,但我建议只需将以下内容添加到代码末尾:

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

这会给你一个 0.5" 的左缩进和一个 0.25" 的悬挂缩进(即使数字看起来有点奇怪).您不需要以 .RightIndent = 开头的中间行,但我想我会在您想要更改它的情况下包含它.

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.

这篇关于应用 ApplyListTemplate 后更改 Word 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆