我希望能在Excel的VBA中从指定的Outlook账户发送邮件,但我的代码出现了问题。我查看了许多论坛,但是还是不能解决问题。
如果有人可以帮助我,我会非常感激。以下是我的代码:
如果有人可以帮助我,我会非常感激。以下是我的代码:
Sub SendMail()
Dim objOutlook As Object
Dim objMail As Object
Dim ws As Worksheet
Set objOutlook = CreateObject("Outlook.Application")
Set ws = ActiveSheet
Dim signature As String
Dim LstRow As Long
LstRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
Dim oAccount As Outlook.Account
For Each oAccount In Outlook.Application.Session.Accounts
If oAccount = "mymail@server.com" Then
For Each cell In ws.Range("A4:A" & LstRow)
Set objMail = objOutlook.CreateItem(0)
signature = objMail.Body
With objMail
.To = cell.Value
.Subject = cell.Offset(0, 1).Value
.Body = cell.Offset(0, 2).Value & vbNewLine & signature
.Attachments.Add cell.Offset(0, 3).Value
.DeferredDeliveryTime = "15/03/2018 10:00:00 PM"
.SendUsingAccount = oAccount
.send
End With
Set objMail = Nothing
Next cell
Else
End If
Next
Set ws = Nothing
Set objOutlook = Nothing
End Sub
.SentOnBehalfOfName
吗? - Maddy.Send
和.Display
在哪里? - Maddy