找到表格(如果找到)

huangapple go评论64阅读模式
英文:

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 ...

huangapple
  • 本文由 发表于 2023年6月12日 14:24:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定