word vba:循环文档重置格式

时间:2011-10-20 13:10:48

标签: vba ms-word format

我想循环浏览我的word文档,删除每个单词上的所有背景颜色。这是我的代码到目前为止,但它无法正常工作 - 我收到以下错误消息“Argument not optional”和“.Item”突出显示:

Sub ResetColor()
Dim doc As Document
Set doc = ActiveDocument
Set eword = doc.Range.Words.Item

 For i = 1 To doc.Range.Words

  eword.Shading.Texture = wdTextureNone
  eword.Shading.ForegroundPatternColor = wdColorAutomatic
  eword.Shading.BackgroundPatternColor = wdColorAutomatic

 Next

End Sub

1 个答案:

答案 0 :(得分:1)

试试这个:

Sub ResetColor()
    Dim doc As Document
    Set doc = ActiveDocument

    For Each eword In doc.Range.Words

      eword.Shading.Texture = wdTextureNone
      eword.Shading.ForegroundPatternColor = wdColorAutomatic
      eword.Shading.BackgroundPatternColor = wdColorAutomatic

    Next

End Sub