通过MailEnvelope发送电子邮件 [英] Send Email via MailEnvelope

查看:600
本文介绍了通过MailEnvelope发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将特定范围复制到邮件中(带有图像).

I want to copy a specific range into mail (with images).

Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
'Working in Excel 2002-2016
Dim AWorksheet As Worksheet
Dim Sendrng As Range
Dim rng As Range

On Error GoTo StopMacro

With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

'Fill in the Worksheet/range you want to mail
'Note: if you use one cell it will send the whole worksheet
Set Sendrng = Worksheets("EMAIL").Range("B2:W41")

'Remember the activesheet
Set AWorksheet = ActiveSheet

With Sendrng

    ' Select the worksheet with the range you want to send
    .Parent.Select

    'Remember the ActiveCell on that worksheet
    Set rng = ActiveCell

    'Select the range you want to mail
    .Select

    ' Create the mail and send it
    ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope

        ' Set the optional introduction field thats adds
        ' some header text to the email body.
        .Introduction = "This is test mail 2."

        With .Item
            .To = ThisWorkbook.Sheets("EMAIL").Range("Z1").Value
            .CC = ThisWorkbook.Sheets("EMAIL").Range("Z1").Value
            .BCC = ""
            .Subject = ThisWorkbook.Sheets("EMAIL").Range("D1").Value
            .Display
        End With

    End With

    'select the original ActiveCell
    rng.Select
End With

'Activate the sheet that was active before you run the macro
AWorksheet.Select

StopMacro:
With Application
    .ScreenUpdating = True
    .EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False

End Sub

为什么MailEnvelope会显示一秒钟而之后什么也没发生?

Why does MailEnvelope show for one second and nothing happen afterwards?

我用.Display替换了.Send,但没有任何变化.另外,我尝试使用RNGtoHTML代码,但是此代码不会复制图像(我在"EMAIL"工作表中有动态链接的图片).

I replaced .Send with .Display but nothing changed. Alternatively I tried to use the RNGtoHTML code but this code does not copy images (I have dynamic linked picture in the sheet "EMAIL").

推荐答案

尝试逐步进行.

运行脚本时,当您到达此代码行时,它将显示

When you run the script, it will display when you get to this line of code,

.display

,但是下面的代码运行了,这将导致它停止显示.

but then the code below is ran and which will cause it to stop displaying.

ActiveWorkbook.EnvelopeVisible = False

如果您单步执行代码,则应该能够看到内容,直到转到上面的代码行为止.

If you step through the code, you should be able to see your content until you get to the line of code above.

这篇关于通过MailEnvelope发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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