gpt4 book ai didi

excel - 将 Excel 图表复制到 Word 文档的末尾

转载 作者:行者123 更新时间:2023-12-04 20:24:09 25 4
gpt4 key购买 nike

我正在尝试将文本和图表从 Excel 复制到 Word。
问题是图表总是出现在 Word 文档的顶部。
如何在 Word 文档末尾添加图表?
这是我的代码:

Sub Test()

Dim tbl As Excel.Range
Dim WordApp As Word.Application
Dim myDoc As Word.Document
Dim WordTable As Word.Table


Set WordApp = GetObject(class:="Word.Application")
WordApp.Visible = True
WordApp.Activate

'Create a New Document
Set myDoc = WordApp.Documents.Add

'Copy Excel Text in cell A1 to A3
Worksheets("Rapportage").Select
Range("A1:A3").Select
Selection.Copy

'Paste Excel Text into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False

'Copy Excel Chart
Worksheets("Rapportage").Select
Range("A4").Select
Selection.Copy

'Paste Chart into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False

End Sub

最佳答案

代替

'Paste Excel Text into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
'Paste Excel Text into MS Word
'add a paragraph at the end of the document and paste into it
with myDoc.Content
.InsertParagraphAfter
.Paragraphs.Last.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
End With

关于excel - 将 Excel 图表复制到 Word 文档的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64473026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com