gpt4 book ai didi

vba - 通过excel vba发送邮件时在outlook中选择帐户

转载 作者:行者123 更新时间:2023-12-02 03:38:54 25 4
gpt4 key购买 nike

<分区>

我想通过 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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com