簡體   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