繁体   English   中英

VBA 直接从 Excel 打开嵌入的 Word 文档

[英]VBA open embedded Word document directly from Excel

I would like to embed a Word document into my Excel file and have the VBA to open it, add a table I have from the Excel file, and copy-paste all in an email. 有没有办法用 VBA 打开嵌入的 Word 文档,而不是提供文件夹路径? 这是我的 VBA(它工作正常)。 我想方法是添加为 object(?)。 谢谢!

Private Sub ToggleButton1_Click()

Dim ol As Outlook.Application
Dim olm As Outlook.MailItem
Dim wd As Word.Application
Dim doc As Word.Document
Dim rng As Range
Set ol = New Outlook.Application
Set olm = ol.CreateItem(olMailItem)
Set wd = New Word.Application
wd.Visible = True
Set doc = wd.Documents.Open(Environ$("USERPROFILE") & "\Desktop\US - Dec.docx")
lr = Sheet4.Range("A" & Application.Rows.Count).End(xlUp).Row
ThisWorkbook.Worksheets("Webinars").Range("A27:D" & lr).Copy
doc.Paragraphs(17).Range.PasteExcelTable _
                        LinkedToExcel:=False, _
                        WordFormatting:=False, _
                        RTF:=False
doc.Content.Copy
With olm
.Display
.To = ""
.Subject = ""
Set Editor = .GetInspector.WordEditor
Editor.Content.Paste
Application.CutCopyMode = False
'.Send
 End With
 Set olm = Nothing
 Application.DisplayAlerts = False
doc.Close SaveChanges:=False
 Set doc = Nothing
wd.Quit
 Set wd = Nothing
 Application.DisplayAlerts = True

End Sub

我在您之前发布的同一问题中为您提供了工作代码的答案。

VBA Excel 开字 Object

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM