英文:
Find table (if found)
问题
我想查看ActiveDocument是否有任何表格。
如果找到任何表格,我将执行一些代码。
如果未找到,则我将执行其他代码。
我不知道如何在Word中查找/未找到表格。
Public HasTable As Boolean
Sub xxx()
' 以某种方式找到表格或未找到表格,并根据是否找到来设置HasTable为True/False
If HasTable = True
' 执行代码
Else
' 执行代码
End If
End Sub
帮助!
英文:
I want to see if the ActiveDocument has any tables.
If any are found then ill execute some code
If NOT found I’ll execute other code.
I don’t know how to find/not find a table in word.
Public HasTable As Boolean
Sub xxx()
' Somehow find a table or not find a table and give HasTable True/False based on if found
If HasTable = True
' Do code
Else
' Do code
End If
End Sub
Help!
答案1
得分: 3
你可以检查文档中表格的数量:
Public Function hasTables(doc As Word.Document) As Boolean
hasTables = doc.Tables.Count > 0
End Function
你可以调用这个函数,例如 IF hasTables(ActiveDocument) then
我不会将其存储在公共变量中。ActiveDocument
可能会更改或插入表格...
英文:
You can check for the number of tables of the document:
Public Function hasTables(doc As Word.Document) As Boolean
hasTables = doc.Tables.Count > 0
End Function
You can call this function e.g. IF hasTables(ActiveDocument) then
I wouldn't store that in a public variable. ActiveDocument
might change or tables get inserted ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论