Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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
Excel 在“中查找文本”;文本框“;_Excel_Vba_Ms Word - Fatal编程技术网

Excel 在“中查找文本”;文本框“;

Excel 在“中查找文本”;文本框“;,excel,vba,ms-word,Excel,Vba,Ms Word,我正在编写一个Excel VBA代码段,它在docx中查找文本字符串。它适用于常规文本,但如果字符串位于docx中的“textbox”中,则找不到该字符串(尽管在MS Word中手动搜索可以验证该字符串是否存在) 您需要在代码中添加类似的内容 Dim shp As Word.Shape For Each shp In ActiveDocument.Shapes If shp.Type = msoTextBox Then If shp.TextFrame.HasText T

我正在编写一个Excel VBA代码段,它在docx中查找文本字符串。它适用于常规文本,但如果字符串位于docx中的“textbox”中,则找不到该字符串(尽管在MS Word中手动搜索可以验证该字符串是否存在)


您需要在代码中添加类似的内容

Dim shp As Word.Shape
For Each shp In ActiveDocument.Shapes
    If shp.Type = msoTextBox Then
        If shp.TextFrame.HasText Then
            'do something
        End If
    End If
Next

您需要在代码中添加类似的内容

Dim shp As Word.Shape
For Each shp In ActiveDocument.Shapes
    If shp.Type = msoTextBox Then
        If shp.TextFrame.HasText Then
            'do something
        End If
    End If
Next

您使用了错误的函数。如您所见,它在
tempDoc.Range
中搜索。如果你需要从文本框中搜索字符串,你应该在文本框集合中的文本框之间进行迭代,并从文本框存在的文本框中提取If。如您所见,它在
tempDoc.Range
中搜索。如果你需要从文本框中搜索字符串,你应该在它们集合中的文本框之间进行迭代,并从存在的文本框中提取If。我以前见过这种代码!可能不需要',iShp作为Word.InlineShape',但是。你是对的,我忘了删除它。。。但现在编辑了。我以前看过这些代码!可能不需要',iShp作为Word.InlineShape',但是。你是对的,我忘了删除它。。。但现在编辑了它。