如何打开嵌入在 Excel 文件中的 Word 对象? [英] How to open a Word object that is embedded in an Excel file?
本文介绍了如何打开嵌入在 Excel 文件中的 Word 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打开并修改嵌入在 Excel 文件中的 Word 文档.
I would like to open and modify a Word document that is embedded in the Excel file.
我需要打开 Word 文档,从范围 A24:C 的 Excel 文件中添加表格 &lastRow,将所有内容复制粘贴到 Outlook 电子邮件中,最后关闭 Word 文档.
I need to open the Word document, add the table from the Excel file from range A24:C & lastRow, copy-paste everything to an Outlook email and finally close the Word document.
我收到错误 13.
Sub SendMail()
Dim ol As Outlook.Application
Dim olm As Outlook.MailItem
Dim wd As Word.Application
Dim doc As Word.Document
Dim rng As Range
Dim oleObject As Object
Dim wordDocument As Object
Set ol = New Outlook.Application
Set olm = ol.CreateItem(olMailItem)
Set wd = New Word.Application
wd.Visible = True
Set doc = wd.Documents.Open(ActiveWorkbook.Sheets("Webinars").OLEObjects(1))
doc.Verb Verb:=xlPrimary
lr = Sheet4.Range("A" & Application.Rows.Count).End(xlUp).Row
ThisWorkbook.Worksheets("Webinars").Range("A24:C" & lr).Copy
doc.Paragraphs(12).Range.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
doc.Content.Copy
With olm
.Display
.To = ""
.Subject = "Test"
Set Editor = .GetInspector.WordEditor
Editor.Content.Paste
CutCopyMode = False
'.Send
End With
Set olm = Nothing
Application.DisplayAlerts = False
CutCopyMode = False
doc.Close SaveChanges:=False
Set doc = Nothing
wd.Quit
Set wd = Nothing
Application.DisplayAlerts = True
End Sub
除了
Set doc = wd.Documents.Open(ActiveWorkbook.Sheets("Webinars").OLEObjects(1))
doc.Verb Verb:=xlPrimary
推荐答案
试试这个:
Sub Demo()
Dim wApp As Word.Application
Dim doc As Word.document
ActiveSheet.Shapes.Range(Array("Object 1")).Select
Selection.Verb Verb:=xlPrimary
Set wApp = GetObject(, "Word.Application")
Set doc = ActiveDocument
MsgBox doc.Paragraphs(1).Range.Text
End Sub
这篇关于如何打开嵌入在 Excel 文件中的 Word 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文