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. Is there a way to open an embedded Word document with VBA instead of giving a folder path? Here is my VBA (it works fine). I guess the way is to add as an object (?). Thanks!
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") & "DesktopUS - 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
question from:
https://stackoverflow.com/questions/65915100/vba-open-embedded-word-document-directly-from-excel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…