Excel/宏/电子邮件。如何从VBA代码中删除循环函数并分别运行每一行?
这是我第一次在这里问问题,我真的很感激如何删除循环并手动逐行运行宏Excel/宏/电子邮件。如何从VBA代码中删除循环函数并分别运行每一行?,excel,vba,email,outlook,Excel,Vba,Email,Outlook,这是我第一次在这里问问题,我真的很感激如何删除循环并手动逐行运行宏 Sub Email() Dim olApp As Object Dim olMail As Object Dim olRecip As Object Dim iRow As Long Dim Recip As String Dim Subject As String iRow = 2 Set olApp = CreateObject("Outlook.Application"
Sub Email()
Dim olApp As Object
Dim olMail As Object
Dim olRecip As Object
Dim iRow As Long
Dim Recip As String
Dim Subject As String
iRow = 2
Set olApp = CreateObject("Outlook.Application")
Do Until IsEmpty(Cells(iRow, 1))
Recip = Cells(iRow, 1).Value
Subject = Cells(iRow, 3).Value
Set olMail = olApp.CreateItem(0)
With olMail
Set olRecip = .Recipients.Add(Recip)
.Display
.CC = ""
.Subject = ""
.HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "summary " & Cells(iRow, 3).Value & " summary" & Cells(iRow, 4).Value & "summary" & "<br>" & "<br>" & "summary" & "<br>" & "<br>" & "conclusion" & .HTMLbody
olRecip.Resolve
.Display
End With
iRow = iRow + 1
Loop
Set olApp = Nothing
Exit Sub
End Sub
注释你的代码
Sub Email() Dim olApp As Object Dim olMail As Object Dim olRecip As Object Dim iRow As Long Dim Recip As String Dim Subject As String
iRow = 2
Set olApp = CreateObject("Outlook.Application")
'If column A has more the 1 email, will send/display email 1 at a time
'Do Until IsEmpty(Cells(iRow, 1))
Recip = Cells(iRow, 1).Value
Subject = Cells(iRow, 3).Value
Set olMail = olApp.CreateItem(0)
With olMail
Set olRecip = .Recipients.Add(Recip)
.Display
.CC = ""
.Subject = ""
.HTMLbody = "<html><body><p>Dear " & Cells(iRow, 2).Value & "," & "<br>" & "<br>" & "summary " & Cells(iRow, 3).Value & " summary" & Cells(iRow, 4).Value & "summary" & "<br>" & "<br>" & "summary" & "<br>" & "<br>" & "conclusion" & .HTMLbody
olRecip.Resolve
.Display
End With
iRow = iRow + 1
'Msgbox to show email was sent or failed
'Loop
Set olApp = Nothing
Exit Sub
End Sub '
你想调试吗?我想你要做的是按F8键进入代码