user366121
user366121

Reputation: 3291

word vba: looping through document resetting format

I want to loop through my word document removing all backgroundcolors on each word. This is my code so far but it is not working - I get the following error message "Argument not optional" and ".Item" is highlighted:

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

Upvotes: 0

Views: 988

Answers (1)

PaulStock
PaulStock

Reputation: 11283

Try this:

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

Upvotes: 1

Related Questions