通过VBA发送电子邮件

时间:2019-05-09 13:09:42

标签: excel vba

我有一些代码可以发送工作表中某个部分的电子邮件。但是,它要求您在电子邮件中登录(在这种情况下为Outlook),是否可以解决此问题?有人对此主题有经验吗?

以下代码用于发送电子邮件:

Sub Mail()

 Dim AWorksheet As Worksheet
 Dim Sendrng As Range
 Dim rng As Range
 Dim antwoord As Integer
 On Error GoTo StopMacro

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

 andwoord = MsgBox("Mail verzenden?", vbYesNo + vbQuestion, "Mail") 
 If andwoord = vbYes Then ElseIf vbNo Then

 GoTo StopMacro End If

 Set Sendrng = Worksheets("Email").Range("A1:D15")

 Set AWorksheet = ActiveSheet

 With Sendrng
     .Parent.Select

     Set rng = ActiveCell
     .Select

     ActiveWorkbook.EnvelopeVisible = True
     With .Parent.MailEnvelope

     'Text in de mail
     .Introduction = "Message"

         With .Item
             .To = 
             .CC = 
             .BCC = 
             .Subject = 
             .Send
         End With

     End With

     rng.Select
 End With

 AWorksheet.Select 0 StopMacro:
 With Application
     .ScreenUpdating = True
     .EnableEvents = True
 End With

 ActiveWorkbook.EnvelopeVisible = False

 End Sub

谢谢您的帮助,彼得

0 个答案:

没有答案