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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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
Vba 在当前Word文档中查找表_Vba_Excel - Fatal编程技术网

Vba 在当前Word文档中查找表

Vba 在当前Word文档中查找表,vba,excel,Vba,Excel,我正在尝试使用VBA编辑Word文档中的表。以下MsgBox返回0,即使文档中有多个表。在宏的其他位置,我正在使用以下命令成功编辑Word文档中的值: With WA.ActiveDocument Set myRange = .Content With myRange.Find .Execute Findtext:="Sally", ReplaceWith:=FirstName, Replace:=1 EndWith EndWith MsgBox(WA.ActiveDocument.Conte

我正在尝试使用VBA编辑Word文档中的表。以下MsgBox返回0,即使文档中有多个表。在宏的其他位置,我正在使用以下命令成功编辑Word文档中的值:

With WA.ActiveDocument
Set myRange = .Content
With myRange.Find
.Execute Findtext:="Sally", ReplaceWith:=FirstName, Replace:=1
EndWith
EndWith
MsgBox(WA.ActiveDocument.Content.Tables.Count)


只需在With语句中使用(如果它们是实际的表)


您可以通过切换到Word文档本身并将以下
Msgbox ActiveDocument.Tables.Count
放在ActiveDocument的ThisDocument部分进行验证。如果答案仍然为0,则您不能使用Word表格。

这样,我从Msgbox ActiveDocument.Tables.Count?和Msgbox.Tables.Count中获得运行时错误424,“需要对象”,并在消息框中使用带零的消息框。在宏结束时,在我查找和替换大量值之后(这些值不在表中)
MsgBox .Tables.Count