【问题标题】:Pasting Multiple excel ranges as a picture in the same Outlook email将多个 Excel 范围粘贴为同一 Outlook 电子邮件中的图片
【发布时间】:2017-08-04 15:05:41
【问题描述】:

这是我用来复制范围以及打开新 Excel 电子邮件的代码。我可以很好地复制和粘贴,但我的问题是,当第二张图片粘贴时,它会替换第一张图片,而不是像我需要的那样粘贴在它上面。我做错了什么?

    Private Sub CommandButton4_Click()
'Finds last Row of email report
Dim lRow As Long
Dim lCol As Long


lRow = Cells.Find(What:="*", _
        After:=Range("A1"), _
        LookAt:=xlPart, _
        LookIn:=xlFormulas, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, _
        MatchCase:=False).row

'Copy range of interest
Dim r As Range
Set r = Sheets("Email").Range(Cells(8, "E"), Cells(lRow, "N"))
r.Copy

'Open a new mail item
Dim outlookApp As Outlook.Application
Set outlookApp = CreateObject("Outlook.Application")
Dim outMail As Outlook.MailItem
Set outMail = outlookApp.CreateItem(olMailItem)

With outMail
    .To = ""
    .CC = ""
    .BCC = ""
    .Subject = shift_txtb2.Text & " " & "Finishing Report" & " " & Format(Now(), "MM/DD/YY")
    .HTMLBody = ""
    'Attachments.Add
    .Display
End With

''Get its Word editor
outMail.Display
Dim wordDoc As Word.Document
Set wordDoc = outMail.GetInspector.WordEditor

''To paste as picture
wordDoc.Range.PasteAndFormat wdChartPicture



Set r = Sheets("Email").Range("P8:T17")
r.Copy
wordDoc.Range.PasteAndFormat wdChartPicture

Unload Me
Sheets(1).Activate
End Sub

【问题讨论】:

标签: vba excel outlook


【解决方案1】:

在粘贴第二个之前放置这个:

 wordDoc.Content.InsertParagraphAfter

你也可以试试:

 wordDoc.Content.TypeParagraph

【讨论】:

  • 不幸的是,这不起作用,但我确实知道你来自哪里。我移动了那条线并在我的代码中尝试了几次,但得到了相同的结果。
  • 我给了你另一个选择。
  • 我不确定我运行的 excel 版本是否与您不同,但我使用第二个选项时收到“未找到方法或成员错误”
  • Excel 的版本无关紧要,因为该方法是 Word 方法。打开 Word 并按录制宏按钮,然后在您的 Word 文档中按Enter,然后停止宏录制。返回您的 VBA 窗口并查看它创建的代码。
猜你喜欢
  • 2021-09-27
  • 1970-01-01
  • 2019-08-02
  • 2020-04-05
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多