将每行发送到Excel

时间:2015-11-01 12:21:17

标签: excel email

我有一张包含以下内容/结构的Excel表格:

Email Address   | Subject | Email Body

user1@abc.com   | ABC XYZ | Information about

user2@abc.com   | XYZ XYZ | System code

我想发送电子邮件至:user1@abc.com,主题(ABC XYC)和电子邮件正文(有关信息)。一旦完成,它应该移动到下一行并执行相同的操作。

我看过this并试过,但没有快乐

一些考虑因素。我想应该暂停一下,也许5封电子邮件。我们说1秒。我最多可以发送500行。

这是我尝试过的代码:

Dim Lastrow as long
dim myemail as string
dim myrange as Range


'counts the number of rows in use
lastrow = Sheets("My Report").Cells(Rows.Count, 1).End(xlUp).Row

    For Each myrange In Sheets("Email Address").Range("A2:A" & lastrow)

        If myrange = "Subject" then

            myEmail = myEmail & myrange.offset(0,1).value & ";"

        End if

       Next Myrange

我的解决方案正在运作。

> Sub SendEmail(what_address As String, subject_line As String,
> mail_body As String)
> 
> Dim olApp As Outlook.Application Set olApp =
> CreateObject("Outlook.Application")
> 
>     Dim olMail As Outlook.MailItem
>     Set olMail = olApp.CreateItem(olMailItem)
>     
>     olMail.To = what_address
>     olMail.Subject = subject_line
>     olMail.Body = mail_body
>     olMail.Send
> 
> End Sub Sub SendMassEmail()
> 
> row_number = 2
> 
> Do DoEvents
>     row_number = row_number + 1
>     Call SendEmail(Sheet6.Range("A" & row_number), Sheet6.Range("D" & row_number), Sheet6.Range("L" & row_number))
>         
>     Loop Until row_number = 102
> 
> End Sub

但是,我想让Loop Until row_number = 102自动找到最后一行。

0 个答案:

没有答案