我想创建一个Excel文件,某些用户可以共享一个文件,并使用共享帐户“ abc@gmail.com”发送群发邮件,并且由于所有用户在Outlook中可能没有相同的帐号,因此,如果代码可以搜索电子邮件而不是帐号,则更好。
单击按钮后没有错误消息,并且消息框“已发送!”单击按钮后成功弹出,但是电子邮件无法成功发送。(我无法从邮箱中找到发送记录)
我整天都在尝试解决此问题,如果有人可以帮助我解决该问题,将不胜感激
Private Sub sendmail_btn_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data")
Set OutApp = CreateObject("Outlook.Application")
Dim i As Integer
Dim last_row As Integer
last_row = Application.WorksheetFunction.CountA(ws.Range("A:A"))
Dim oAccount As Outlook.Account
For Each oAccount In Outlook.Application.Session.Accounts
If oAccount = "abc@gmail.com" Then
For i = 2 To last_row
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = ws.Range("A" & i).Value
.CC = ws.Range("B" & i).Value
.BCC = ws.Range("C" & i).Value
.Subject = "Testing in progress - " & Cells(i, 4).Value
.HTMLBody = "email body"
Set .SendUsingAccount = oAccount
.Send
End With
Next i
Else
End If
Next
MsgBox "Sent!"
Set ws = Nothing
Set OutApp = Nothing
End Sub