将模板从Excel复制到Outlook [英] Copying a template from Excel to Outlook

查看:118
本文介绍了将模板从Excel复制到Outlook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个固定在excel文件中的模板.单击预览按钮后,此模板将在Outlook及其主题,主题等中显示.

我有这段代码可以正常工作,但不能在body字段中工作.

  Sub PreviewMail()昏暗的objMail,objOutLook作为对象Dim rngTo,rngCC,rngBCC,rngBody作为范围昏暗的行昏暗的整数设置objOutLook = CreateObject("Outlook.Application")设置objMail = objOutLook.CreateItem(0)设置main = ThisWorkbook.Sheets("Main")lRow = main.Cells(Rows.Count,2).End(xlUp).Row对于i = 11 To lRow与主要设置rngTo = .Range("B"& i)设置rngBody = .Range(.Range("C10:N30"),.Range("C10:N30"))结束于使用objMail.To = rngTo.Value.Subject =样本"'我喜欢rngbody在这里.HTMLBody = RangetoHTML(rngBody)',来自Ron de Bruin网站.展示结束于接下来我结束子 

这是位于上述范围内的模板.

谁能帮我解决这个问题?我已经尝试了来自罗恩·德·布鲁因(Ron de Bruin)的

I have a template that is stationed in an excel file. Once I click the preview button, this template will be displayed in outlook as well as its subject, to and etc.

I have this code that works fine but is not working in the body field.

Sub previewMail()
Dim objMail, objOutLook As Object
Dim rngTo, rngCC, rngBCC, rngBody As Range
Dim lRow As Long
Dim i As Integer


Set objOutLook = CreateObject("Outlook.Application")
Set objMail = objOutLook.CreateItem(0)
Set main = ThisWorkbook.Sheets("Main")

lRow = main.Cells(Rows.Count, 2).End(xlUp).Row

For i = 11 To lRow
    With main
        Set rngTo = .Range("B" & i)
        Set rngBody = .Range(.Range("C10:N30"), .Range("C10:N30")) 
    End With

    With objMail
        .To = rngTo.Value
        .Subject = "Sample"
        'i like the rngbody to be here
        .HTMLBody = RangetoHTML(rngBody)' from Ron de Bruin site
        .Display

    End With
Next i
End Sub

This is the template stationed in the said range above.

Can anyone please help me figure this out? I have tried this from Ron de Bruin but I can't make it work. This only gives a product that is an "invisible table".

解决方案

Try Range.PasteAndFormat wdChartPicture

Example

Option Explicit
Sub previewMail()
    Dim objMail, Main, objOutLook As Object
    Dim rngTo, rngCC, rngBCC, rngBody As Range
    Dim lRow As Long
    Dim i As Integer
    Dim wordDoc As Word.Document '<---

    Set objOutLook = CreateObject("Outlook.Application")
    Set objMail = objOutLook.CreateItem(0)
    Set Main = ThisWorkbook.Sheets("Main")
    Set wordDoc = objMail.GetInspector.WordEditor '<---

    lRow = Main.Cells(Rows.count, 2).End(xlUp).Row

    For i = 11 To lRow
        With Main
            Set rngTo = .Range("B" & i)
            Set rngBody = .Range(.Range("C10:N30"), .Range("C10:N30"))
            rngBody.Copy '<---
        End With

        With objMail
            .To = rngTo.Value
            .Subject = "Sample"
            .Display
             wordDoc.Range.PasteAndFormat wdChartPicture '<---
             ' Or
             'wordDoc.Range.PasteAndFormat wdChartPicture & .HTMLBody = " "
        End With
    Next i
End Sub

Make sure to set references to the Microsoft Outlook and Microsoft Word Object libraries

Tools > References...

这篇关于将模板从Excel复制到Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆