|
本帖最后由 yueyong2008 于 2010-10-20 21:05 编辑
----------------------
以下是一段在EXCEL中利用宏发送邮件的代码:
功能是按照工作表A列各行提供的地址,将各行B列的数据发送至各地址中
!!当运行以下数据时,总报错“next 没有for",麻烦高手给我修改一下,谢谢!
----------------------
Public Sub mail()
Dim n As Integer, i As Integer
Dim ws As Worksheet
Dim outlookapp As Outlook.Application
Dim newmail As Outlook.MailItem
Set outlookapp = New Outlook.Application
Set ws = Worksheets("sheet1")
n = ws.Range("A65536").End(xlUp).Row
For i = 2 To n
Set newmail = outlookapp.CreateItem(olMailItem)
With newmail
.Subject = "HAHA"
.Body = "HAHA" & ws.Range("b" & i)
.To = ws.Range("a" & i)
.Send
Next i
Set ws = Nothing
Set newmail = Nothing
Set outlookapp = Nothing
End Sub
|
|