-4
發送郵件EXCEL我是很新的VBA。我有一個已經開發了一個Excel工作表,其中我有作爲然後再進行附加任務:使用VBA
我需要創建一個電子郵件按鈕,點擊該按鈕,整個工作表應郵寄到指定的收件人,也允許我添加一個附件。
發送郵件EXCEL我是很新的VBA。我有一個已經開發了一個Excel工作表,其中我有作爲然後再進行附加任務:使用VBA
我需要創建一個電子郵件按鈕,點擊該按鈕,整個工作表應郵寄到指定的收件人,也允許我添加一個附件。
你好Aakash Sehgal的,
Sendmail()
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 = "Aakash Sehgal"
.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 by use:
'.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
做以下幾列的ActiveSheet列表:
在列A:人的名稱
在B列:E-mail地址
在列C:是或沒有(如果該值是它會創建一個郵件)
通過對Activesheet每一行和每一宏觀循環,如果在B列
和「是」,在C列,將創建一個郵件的電子郵件地址中包含了一個每個人的提醒。
如果你有在列重複的地址看看這個例子。
這是一個例子,你可以怎麼做,但如果你不是要手工添加的smtp的是,可能太看看這裏:
Sub SMTP_Mail_SEND()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
' Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
' = "Fill in your SMTP server here"
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
With iMsg
Set .Configuration = iConf
.To = "[email protected]"
.CC = ""
.BCC = ""
.From = """daniel"" <[email protected]>"
.Subject = "This is a mail generated by use manually smtp mail"
.TextBody = strbody
.Send
End With
End Sub
來源: http://www.rondebruin.nl/win/s1/cdo.htm
乾杯
DanielElmnäs
請發表您的代碼,或者我們不能幫你 – TylerDurden
我建議你這個網站:http://www.rondebruin.nl/win/section1.htm有很多例子來說明如何使用VBA在Excel中一個郵件發送。 –
https://stackoverflow.com/search?q=[vba]+send+mail –