查找函数 VBA 未找到命名参数

问题描述 投票:0回答:1

我正在编写一个宏,该宏运行在 Word 文档中,并突出显示 Excel 单元格区域中包含的所有值。我使用了 find 函数,该函数工作正常,直到我添加参数 IgnoreSpace:= True ,我不明白为什么它会导致错误。感谢任何帮助

    Sub Highlight()
    Dim lrow As Long
    lrow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
     Dim i As Long
       Dim myRange As Object
        Dim FindText As Object

        Set myRange = ActiveDocument.Content


       For i = 1 To lrow Step 1

       myRange.Find.Execute FindText:=Sheet1.Range("A" & i).Value, MatchCase:=False, 
        IgnoreSpace:=True, Forward:=True, MatchWholeWord:=True

      If myRange.Find.Found = True Then myRange.HighlightColorIndex = wdYellow
      Next i
      End Sub
excel vba ms-word
1个回答
0
投票

上面的代码看起来就像您在 MatchCase:=False 之后按 Enter 键开始新行,然后缩进。该 CR 中断了 Execute 参数并留下不完整的行。匹配 448:“未找到命名参数”。

 myRange.Find.Execute FindText:=Sheet1.Range("A" & i).Value, MatchCase:=False, 
        IgnoreSpace:=True, Forward:=True, MatchWholeWord:=True

追加空格+下划线+回车。 在此处查看有关添加评论等的指导。你的台词变成:

 myRange.Find.Execute FindText:=Sheet1.Range("A" & i).Value, MatchCase:=False, _ 
        IgnoreSpace:=True, Forward:=True, MatchWholeWord:=True
© www.soinside.com 2019 - 2024. All rights reserved.