2012-06-14 54 views
1

我有這個例程,運行良好,但它會因爲它計數段落標記而混亂。我怎樣才能跳過段落標記?如何避免段落標記?

 For Each wrd In ActiveDocument.Words 
      If Selection.Style = ActiveDocument.Styles("Normal") Then 
       If wrd.Font.Name <> "Arial" Or wrd.Font.Size < 9 Or wrd.Font.Size = 11 Or wrd.Font.Size > 12 _ 
       Or wrd.Font.Color <> wdColorBlack Or wrd.Font.Color <> wdColorAutomatic Or wdColorBlue Then 
        wrd.HighlightColorIndex = wdYellow 
        wordrep = wordrep + 1 
       End If 
      End If 
     Next 

回答

1

試試這個

For Each wrd In ActiveDocument.Words 
    If Selection.Style = ActiveDocument.Styles("Normal") Then 
     If wrd.Font.Name <> "Arial" Or _ 
      wrd.Font.Size < 9 Or _ 
      wrd.Font.Size = 11 Or _ 
      wrd.Font.Size > 12 _ 
      Or wrd.Font.Color <> wdColorBlack Or _ 
      wrd.Font.Color <> wdColorAutomatic Or _ 
      wrd.Font.Color <> wdColorBlue Then 
       If Asc(Left(wrd, 1)) <> 13 Then 
        wrd.HighlightColorIndex = wdYellow 
        wordrep = wordrep + 1 
       End If 
     End If 
    End If 
Next 
+0

這就像往常一樣完美,Siddharth!非常感謝你! – MBlackburn

1

有什麼問題你的邏輯。你是什​​麼意思Or wdColorBlue Then?如預期這將無法正常工作......

如果你的意思wrd.Font.Color <> wdColorBlue:字體顏色不能黑色和藍色在同一時間,所以wrd.Font.Color <> wdColorBlack Or wrd.Font.Color <> wdColorBlue總是是真的!因此,內部If構造的內容將始終執行。

如果你的意思是wrd.Font.Color = wdColorBlue:當字體是藍色時,它不一定是黑色的,所以wrd.Font.Color <> wdColorBlack條件是多餘的和多餘的。

我不知道這是否解決了您的問題......我並不完全確定您的意思是「它會忽略段落標記」。