我想問一下如何從列到行更改Ron de Bruins代碼(例如,行1包含名稱;行2的電子郵件;行3反映了是或否)。給一個範圍(行)中的每個人發郵件
Sub Test1()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("B").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "C").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "A").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date"
'You can add files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
非常感謝你提前!
謝謝您的回覆!假設第18行(H18:AE18)包含電子郵件地址(由第19行{name}&「@ yahoo.com」派生),並且「是」或空白符號位於第20行,這仍然適用,因爲我更改了列(「B」)改爲「H」? –
代碼正在循環訪問SpecialCells(xlCellTypeConstants).Areas中的一組單元格。因此,如果數據符合我在代碼下面提到的標準,那麼它也適用於H列。 – sktneer