如何将excel复制/粘贴桌复制到Word文档
我想从Excel表将桌子复制到.docx。我有一个单词#tableauxvdd,我想用表代替。
所以我写了这个代码
With word_fichier.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "#tableauxvdd"
.Replacement.Text = "#tableauxvdd"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceNone
End With
If .Find.Found = True Then
For i = 1 To nombre_de_vdd
Set tblRangeVdd = ThisWorkbook.Worksheets("Info vdd " & i).Range("A1:C6")
tblRangeVdd.Copy
.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
Next
End If
End With
I want to copy/paste tables from an Excel sheet toward a .docx. I have a word #tableauxvdd which I want to replace by my tables.
So I wrote this code
With word_fichier.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "#tableauxvdd"
.Replacement.Text = "#tableauxvdd"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceNone
End With
If .Find.Found = True Then
For i = 1 To nombre_de_vdd
Set tblRangeVdd = ThisWorkbook.Worksheets("Info vdd " & i).Range("A1:C6")
tblRangeVdd.Copy
.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
Next
End If
End With
But its not working. Here is the tables I need to copy/paste
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当您编写代码以自动化单词时,您都需要考虑执行UI中的任务时将采取的步骤。
在Word文档中,表始终由段落分开,因此您的代码也需要做同样的操作。
例如:
您还需要以相反的顺序添加表,例如:
Whenever you write code to automate Word you need to think through what steps you would take if you were performing the task in the UI.
In a Word document, tables are always separated by a paragraph, so your code needs to do the same.
For example:
You'll also need to add the tables in reverse order, for example: