vba 如何在 word 宏中选择多个项目符号列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11981091/
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
How do I select multiple bullet lists within word macro
提问by nicemanda
I am trying to find all instances of bulleted lists within a large selection of a word doc and assign them a style as per our company branding.
我试图在大量选择的单词文档中找到项目符号列表的所有实例,并根据我们公司的品牌为它们分配样式。
I have gotten pretty close, the following Macro selects the first line in the first bulleted list in the selection and assigns it the style I require.
我已经非常接近了,以下宏选择了选择中第一个项目符号列表中的第一行,并为其分配了我需要的样式。
I just need some help getting it to select all the bullets in the doc.
我只需要一些帮助来让它选择文档中的所有项目符号。
Sub findbullets22()
'findbullets22 Macro
Dim oPara As Word.Paragraph
With Selection
For Each oPara In .Paragraphs
If oPara.Range.ListFormat.ListType = _
WdListType.wdListBullet Then
oPara.Range.Select
End If
Next
End With
Selection.Style = ActiveDocument.Styles("List Paragraph")
End Sub
回答by Siddharth Rout
Like this? You have to set style inside the loop and not outside the loop.
像这样?您必须在循环内而不是在循环外设置样式。
Sub findbullets22()
Dim oPara As Word.Paragraph
With Selection
For Each oPara In .Paragraphs
If oPara.Range.ListFormat.ListType = WdListType.wdListBullet Then
oPara.Range.Style = ActiveDocument.Styles("List Paragraph")
DoEvents
End If
Next
End With
End Sub
回答by cbjayakumar
This might help you:
这可能会帮助您:
With seletion
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.ListFormat.ListType = WdListType.wdListBullet Then
oPara.Range.Select
oPara.style = ActiveDocument.styles("List Paragraph")
End If
Next
End With
回答by Suril Mehta
Below is a macro to select all bullets:
下面是一个选择所有项目符号的宏:
Sub SelectBullets()
On Error Resume Next
Dim Para As Word.Paragraph
With ActiveDocument
.DeleteAllEditableRanges (-1)
For Each Para In .Paragraphs
If Para.Range.ListFormat.ListType > 0 Then
Para.Range.Editors.Add (-1)
End If
Next
.SelectAllEditableRanges (-1)
.DeleteAllEditableRanges (-1)
End With
End Sub
Once selected, you can uniformly modify all bullets.
选择后,您可以统一修改所有项目符号。
Para.Range.ListFormat.ListType > 0 - this command specifies that each and every type of bullet or numbered list is to be selected. Para.Range.Editors.Add (-1) - this command adds the relevant selection to range .SelectAllEditableRanges (-1) - this command selects all ranges added
Para.Range.ListFormat.ListType > 0 - 此命令指定要选择每种类型的项目符号或编号列表。Para.Range.Editors.Add (-1) - 此命令将相关选择添加到范围 .SelectAllEditableRanges (-1) - 此命令选择添加的所有范围
For additional useful word macros, please visit my video available at the following link https://youtu.be/p_ZhufliFw8
有关其他有用的单词宏,请访问以下链接中我提供的视频 https://youtu.be/p_ZhufliFw8
Regards, Suril Mehta
问候,苏里尔·梅塔