VBA:如何在 Word 中开始和结束带有项目符号或编号的列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26280070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA: How to start and end a list, bulleted or numbered, in Word?
提问by tincanfury
I just can't figure out how to get VBA to start a bulleted list in Word. I've got some code that types out stuff into word, I can get font and paragraph formatting, no problem, but now I want to create a bulleted list. I've found the following code,
我只是不知道如何让 VBA 在 Word 中启动项目符号列表。我有一些代码可以将内容输入到 word 中,我可以获得字体和段落格式,没问题,但现在我想创建一个项目符号列表。我找到了以下代码,
ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(2)
ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdBulletGallery).ListTemplates(2)
which should create a bulleted list of the second standard type, but all I can determine is to use it with a 'Range' command which causes the entire document to have the list applied to it. What I'd like to do is have it applied just to the new line that I'm having the code type, and then, at some point, be able to turn the list off, to be able to continue without the list being applied.
这应该创建第二个标准类型的项目符号列表,但我所能确定的是将它与“范围”命令一起使用,这会导致整个文档应用该列表。我想要做的是将它仅应用于我拥有代码类型的新行,然后在某个时候能够关闭列表,以便能够在不应用列表的情况下继续.
Thanks!
谢谢!
回答by Petay87
This link should help you with your query:
此链接应该可以帮助您进行查询:
Basically this code applies it to a selection:
基本上此代码将其应用于选择:
Selection.Range.ListFormat.ApplyBulletDefault
And this code adds it to the selected paragraph number (in this case paragraph 2):
此代码将其添加到选定的段落编号(在本例中为第 2 段):
Documents("MyDoc.doc").Paragraphs(2).Range.ListFormat _
.ApplyBulletDefault
This code applies the Bullet points to a range of paragraphs:
此代码将项目符号点应用于一系列段落:
Set myDoc = ActiveDocument
Set myRange = myDoc.Range( _
Start:= myDoc.Paragraphs(3).Range.Start, _
End:=myDoc.Paragraphs(6).Range.End)
If myRange.ListFormat.ListType = wdListNoNumbering Then
myRange.ListFormat.ApplyBulletDefault
End If
Assuming you know the text that is being added, you can use the second example. If you don't know how many paragraphs are being added, then each time you create a new one, increment an integer by 1 and use that integer in the third example.
假设您知道要添加的文本,您可以使用第二个示例。如果您不知道添加了多少段落,那么每次创建一个新段落时,将一个整数加 1,并在第三个示例中使用该整数。
For Example:
例如:
Start:= myDoc.Paragraphs(2).Range.Start, _
End:=myDoc.Paragraphs(i).Range.End)