简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM