VB 脚本运行时错误:5941 请求的集合成员不存在

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

我在 Word 文档(启用宏或 .docm)中有一个现有的 tabale,我正在尝试向表中添加行。但我遇到运行时错误。

Private Sub Method1()

Dim tbl As Table
Dim rowtbl as Row

Set tbl = ActiveDocument.Tables(2)
Set rowtbl = tbl.Rows.Add(BeforeRow:=tbl.Rows(1)) ---> At this line we are getting runtime error
Set coltbl = tbl.Columns.Add(BeforeColumn:=tbl.Columns(1)) ---> At this line we are getting runtime error
End Sub

我已按照以下步骤解决了该错误。

  1. ActiveDocument.Tables(1).Rows.Add BeforeRow:=ActiveDocument.Tables(1).Rows(rowCnt)
  2. tbl .Rows.Add BeforeRow:=tbl .Rows(rowCnt)
  3. tblNew.Tables(1).Columns.Add BeforeColumn:=tblNew.Tables(1).Columns(1)
  4. ActiveDocument.Tables(1).Columns.Add BeforeColumn:=ActiveDocument.Tables(1).Columns(rowCnt) 我们遇到了与上述单词相同的运行时错误。

我已遵循 MSDN 中的以下参考。 https://learn.microsoft.com/en-us/office/vba/api/word.columns https://learn.microsoft.com/en-us/office/vba/api/word.rows

我为启用宏的文档提供的参考文献如下。 References

ms-word vbscript
© www.soinside.com 2019 - 2024. All rights reserved.