嘿伙计们我试图通过excel发送电子邮件遇到了问题。我正在尝试从excel发送一封电子邮件,其中显示时间表为shown。
周五我能够收到要发送的电子邮件,但现在它似乎没有用。也许它只需要一段时间发送我不确定。
如果可能的话,我希望能够发送颜色范围,我不确定是否可行。
非常感谢任何帮助
Private Sub SendEmail()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OlObjects = OutApp.GetNamespace("MAPI")
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = ("xxxx@hotmail.com")
.Subject = "Test Mail"
.Body = "This is a test email." & Time ' Time refers to a range of cells e.g. a1:h15
.Display
.Send
End With
End Sub
答案 0 :(得分:1)
在这里尝试一下。这是我从之前的程序中编写的内容,与您正在进行此操作的样式相同。如果你使用.Send
,你会感到厌倦,你需要" OK"来自Outlook的弹出窗口。
'-------Send Mail----------
strbody = "TEST:" & strbody 'Build header.
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "test@something.com" 'Email to be sent to here.
.cc = ""
.BCC = ""
.Subject = "Test! " & Format(Date, "mmm-dd-yy")
.Body = strbody
.attachments.Add ActiveWorkbook.FullName
.Display 'Can use .Send however it will ask for verification within outlook
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing