2012-08-16 28 views
0

我正在嘗試在大量單詞文檔中查找項目符號列表的所有實例,並根據我們公司的品牌爲其分配樣式。如何在單詞宏內選擇多個項目符號列表

我已經非常接近了,下面的宏選擇選擇中第一個項目符號列表中的第一行,併爲其指定我需要的樣式。

我只需要一些幫助讓它選擇文檔中的所有項目符號。

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 

回答

1

是這樣的?你必須在循環內設置樣式,而不是在循環之外。

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 
+0

亞洲時報Siddharth嗨 - 非常感謝你的幫助,我要把它放到我的文檔,現在情況是前兩個項目符號列表得到的風格,其餘被刪除。 – nicemanda 2012-08-16 06:20:28

+0

任何想法爲什麼這可能會發生?非常感謝你提供的任何見解:) – nicemanda 2012-08-16 06:21:14

+0

線索在這裏'With Selection'如果子彈不在選擇中,那麼它們將被忽略;) – 2012-08-16 06:24:41

1

這可以幫助你:

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 
+0

如果你也解釋一下代碼的功能會更好。 – 2012-10-24 09:51:21

+1

這解釋了在任何地方的文檔中的子目錄更改爲「列表段落」樣式。正如nicemanda想要的。 – cbjayakumar 2012-10-24 11:39:57

0

下面是宏選擇所有子彈:

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 

一旦選中,就可以統一修改所有的子彈。

Para.Range.ListFormat.ListType> 0 - 此命令指定要選擇每種類型的項目符號或編號列表。 Para.Range.Editors.Add(-1) - 此命令將相應的選擇範圍,以 .SelectAllEditableRanges(-1) - 此命令將選擇所有範圍添加

有關其他有用的字宏,請訪問可用我的視頻通過以下鏈接 https://youtu.be/p_ZhufliFw8

問候, Suril梅塔

相關問題