【发布时间】:2021-06-13 16:10:49
【问题描述】:
我有一段代码在多次运行时只会产生格式错误。
该应用程序的目的是从另一个文档中复制表格行并将其粘贴到主文档中的特定表格中。在另一个文档中,除了此表行之外没有其他内容。
现在的错误如下: 该表有两列。第一行被正确附加,但第二行作为一个完整的块粘贴到第一个单元格中,因此第二列既没有创建也没有填充。如果我追加更多行,它们总是嵌套并插入到第一个单元格中。
截图:
Dim wddoc As Document
If CheckBox700400.Value = True Then
Set wddoc = Documents.Open(file1)
wddoc.Activate
With ActiveDocument:
Selection.WholeStory
Selection.Copy
End With
ThisDocument.Activate
With Selection:
.GoTo what:=wdGoToTable, Count:=4
.GoTo what:=wdGoToLine
.PasteAndFormat (wdTableAppendTable)
End With
wddoc.Close
End If
If CheckBox700300.Value = True Then
Set wddoc = Documents.Open(file2)
wddoc.Activate
With ActiveDocument:
Selection.WholeStory
Selection.Copy
End With
ThisDocument.Activate
With Selection:
.GoTo what:=wdGoToTable, Count:=4
.GoTo what:=wdGoToLine
.PasteAndFormat (wdTableAppendTable)
End With
wddoc.Close
End If
感谢您的帮助!
【问题讨论】:
-
“在另一个文档中,除了这个表格行之外没有别的了。”这种说法是不正确的。包含单行表格的文档还包含位于表格之后的空段落。在选择整个文档时,您将同时复制表格和最后的空白段落。
标签: vba automation ms-word