通过MailEnvelope发送电子邮件(VBA,Excel)
我想创build一个macros,将特定范围复制到Outlook(带图像)。 但它不工作就像我想要…
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只显示1秒,之后什么也没有发生? 似乎不适合我。
我用.displayreplace了.send,但仍然没有任何变化。 另外我试图使用RNGtoHTML代码,但这个代码不复制图像(我有dynamic链接的图片在表“EMAIL”)。
你的问题是你使用
。显示
但不要等待发送,然后closures信封而不发送:ActiveWorkbook.EnvelopeVisible = False
- 只是评论它,对话框将留在那里给你发送它。
如果您需要使用.Send或.Display完全不起作用:
- 在pipe理模式下运行outlook解决了这个问题
- 改变程序访问*的MS Outlook设置为“警告我,如果..”解决了我的一种(使用。发送时显示恼人的对话框)
-
把MsgBox Err.description放在最后来debugging你的错误
MsgBox Err.description End Sub
-
仍然试图找出实际的解决scheme 。
邮件发送macros为我工作,但之后停止。 不知道为什么。 我甚至试图添加一些registry项( https://social.technet.microsoft.com/Forums/ie/en-US/e2c89fec-beb3-4224-a6cb-112704406907/cannot-change-programmatic-access-security?forum =outlook )。 但是这没有用。
*最有趣的是,如果您禁用MS Outlook警告程序访问( https://www.slipstick.com/developer/change-programmatic-access-options/ ) – 在pipe理中启动MS O并转到该设置 -它停止显示warnig,但也停止请求和function。 通常的微软行为这些天….