发送最后一行/其他行的不同电子邮件

时间:2015-09-24 17:16:18

标签: excel vba

我需要修改现有的宏来执行以下功能:

  1. 应该可以选择输入草稿电子邮件所需的行数。
  2. 宏应包括最后一行加上输入的行数
  3. (例如,我输入“5”表示最后一行+上面4行)。

    1. 应为每一行草拟个人电子邮件。
    2. (例如,最后一行是Mailto = Colleague3@hotmail.com; MailSubject =“EmailSubject_As_Per_the_Cell”Mailbody =“Hi Friend3,我邀请您参加今天举行的会议。”

      1. 其他细节应保留原样。 (例如签名等)
      2. 注意:我的Excel工作表有6-7列,其中包含所有项目编号/编号/参演者姓名/参加者姓名等。

        我尝试使用VBA代码调整但我无法完成它。

        Sub Mail_Outlook()
            Dim OutApp As Object
            Dim OutMail As Object, signature As String
            Dim irow As Integer
        
            Dim objItem As Object
            irow = InputBox("How many Invites do you want to send?")
        
            LastRow = ActiveSheet.Range("E" & Rows.Count).End(xlUp).Row
        
            If Cells(LastRow, 1).Value <> "" Then
                Mailto = Cells(LastRow, 1).Offset(0, 5).Value
                If Mailto = "Colleague1" Then Mailto = "Colleague1@hotmail.com"
                If Mailto = " Colleague2" Then Mailto = " Colleague2@hotmail.com"
                If Mailto = " Colleague3" Then Mailto = " Colleague3@hotmail.com"  
            End If
        
            MailSubject = Cells(LastRow + irow, 1).Offset(0, 4).Value & " – Important Message"
        
            MailBody = "Hi " & Cells(LastRow, 1).Offset(0, 5).Value & "," & vbNewLine & vbNewLine & _
            " I’m inviting you for the conference being held today." & _
            vbNewLine
        
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(o)
        
            With OutMail
                 .Display
            End With
        
            signature = OutMail.body
            With OutMail
                .Subject = MailSubject
                .To = Mailto
                .body = MailBody & vbNewLine & signature
            End With
        
            Set OutMail = Nothing
            Set OutApp = Nothing
        
        End Sub
        

1 个答案:

答案 0 :(得分:0)

我假设您已正确处理Outlook内容...这看起来实际上并没有发送任何电子邮件,只是创建可以发送的电子邮件?

看看这些变化是否会让您更接近您的追求。这段代码经过了轻度测试,但绝不是防弹的。

devs