将 Excel 工作表复制到 Word
我需要将“GreatIdea”工作表导出到 Word 文档。 “GreatIdea”分为多个页面,我的专栏基于这些页面。
A - C 包含目录,D - F 包含第 1 章,...
Sub test()
' Open LOL.docx'
Dim appWD As Word.Application
Set appWD = New Word.Application
Dim docWD As Word.Document
Set docWD = appWD.Documents.Open("C:\Users\TOM\Desktop\LOL.docx")
docWD.Activate
Sheets("Sheet1").Select
' Copy from GreatIdea to LOL.docx'
Range("A1:K40").Copy
appWD.Selection.PasteSpecial
appWD.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "/" & "OEF_OFFERTE"
appWD.ActiveDocument.Close
appWD.Quit
Set appWD = Nothing
Set docWD = Nothing
End Sub
这会将所有内容复制到 Word 中,但不会复制列布局。复制所有内容的其他解决方案也被接受。我只需要确保复制每列的所有数据。
迈克的回答编辑:
Range("A1:C40").Copy
appWD.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
I need to export the sheet 'GreatIdea' to a Word document. 'GreatIdea' is divided into pages and my columns are based on these pages.
A - C contain a table of contents, D - F contain chapter 1, ...
Sub test()
' Open LOL.docx'
Dim appWD As Word.Application
Set appWD = New Word.Application
Dim docWD As Word.Document
Set docWD = appWD.Documents.Open("C:\Users\TOM\Desktop\LOL.docx")
docWD.Activate
Sheets("Sheet1").Select
' Copy from GreatIdea to LOL.docx'
Range("A1:K40").Copy
appWD.Selection.PasteSpecial
appWD.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "/" & "OEF_OFFERTE"
appWD.ActiveDocument.Close
appWD.Quit
Set appWD = Nothing
Set docWD = Nothing
End Sub
This copies everything into Word, but doesn't copy the column layout. Other solutions to copy everything are accepted too. I just need to make sure all the data from every column gets copied.
Mike's answer edited:
Range("A1:C40").Copy
appWD.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 WORD 应用程序 (AppWD) 时,有一个更好的功能:
尝试其中之一
祝您好运 - MikeD
As you are in a WORD application (AppWD), there's a better function:
Try one of these
Good luck - MikeD