我在Word中运行一个宏,其中包括在文档中已存在的表的底部添加一行并填充某些单元格。奇怪的是,对于它工作的大多数文档,但是有几个文档我收到了运行时错误91.
'Update the document properties, updates the header, updates the table of contents,
' and adds a file to the Version History table.
Sub zzAddVersionHistory(strUsuario As String, strDescripcion As String)
Dim newDate As String
Dim rowNumber As Integer
Dim rowNew As Row
Dim strIssue As String
Dim ascIssue As Integer
'Updates the Date property
newDate = Format(Date, "dd/MM/yyyy")
ActiveDocument.CustomDocumentProperties("Date").Value = newDate
'Finds the version from the Issue property and updates the version
If DocPropertyExists("Issue") = True Then
strIssue = ActiveDocument.CustomDocumentProperties("Issue").Value
ascIssue = (Asc(strIssue)) + 1 'Convierte el Issue en ascii y le suma uno
strIssue = Chr(ascIssue) 'Convierte el ascii en caracter
ActiveDocument.CustomDocumentProperties("Issue").Value = strIssue
End If
'Updates Header and footer
zzActualizarHeaderFooter
'Updates Fields
zzActualizarCampos
'Accepts changes in header y footer
zzAcceptChangesInHeaderFooter
'Adds a row to the table
rowNumber = Application.ActiveDocument.Tables(1).Rows.Count
Set rowNew = Application.ActiveDocument.Tables(1).Rows.Add
'Inserts KTC Issue In first cell of the new row
rowNew.Cells(1).Range.InsertAfter (strIssue) ''' Runtime-error here
'Inserts Issued By in the third cell of the new row
rowNew.Cells(3).Range.InsertAfter (strUsuario)
'Inserts the Date in the fourth cell of the new row
rowNew.Cells(4).Range.InsertAfter (newDate)
'Inserts Description of Changes in the fifth cell of the new row
rowNew.Cells(5).Range.InsertAfter (strDescripcion)
'Updates the Table of Contents
zzActualizarIndices
End Sub
如果需要,我可以提供宏调用的子功能,但我不认为他们与此问题有任何关系。 我认为问题出现在那些文档的某个地方,表格格式,但我无法在任何地方找到解释,也没有找到与其他文档中的表格有任何区别。
答案 0 :(得分:0)
嵌套表会搞乱单元格集合。一旦手动合并/拆分最后一行的单元格,然后添加一个新行,就会变成...... 不同的。保存为rtf,查看代码,抓住你的头脑。
使用一个(第一个?第二个?)"标准"行计数列并调整代码,以防最后一行的列数/单元格数与#34; norm"不同。使用"选择"和一个断点来调查麻烦的表格,以了解如何处理这些特殊情况。