Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
word vba:循环文件重置格式_Vba_Ms Word_Format - Fatal编程技术网

word vba:循环文件重置格式

word vba:循环文件重置格式,vba,ms-word,format,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 = wd

我想循环浏览我的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
试试这个:

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

我收到一条错误消息“Command not available”(命令不可用),虽然宏正确启动,但eword.Shading.Texture=WDTextureOne会高亮显示。如果文档受保护或为只读,则会发生此错误。确保您对文档具有写访问权限。嗯。否该文档不受保护且不是只读的。两者都选中,但它在新文档上工作,因此宏可以工作。谢谢。