i'm new to VBA and im trying to write a macro that automates mail sending from mail list (using outlook15), and attaching a pdf file to them.
i wrote the following script, that loops thrugh 16 cells with mail addresses, and attaches pdf files ( via path).
for some reason i am getting the following message:
"run time error '-2146959355(80080005)':
server execution failed"
.
when i hit debug, the row :
"Set outlookapp = CreateObject("Outlook.Application")"
is being highlited.
any ideas how to solve it?
Sub SndEmail()
'define variables and their types'
Dim address As String
Dim subject As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As String
Dim attachment As String
'x will be row index we loop through'
Dim x As Integer
x = 61
Do While x < 77
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.CreateItem(0)
Set myAttachments = outlookmailitem.Attachments
'taking the file path from cells in excel'
path = sheet1.Cells(x, 4)
address = sheet1.Cells(x, 3)
subject = "hello world"
attachment = path
outlookmailitem.To = address
outlookmailitem.CC = ""
outlookmailitem.BCC = ""
outlookmailitem.subject = subject
'taking the body content from cell 56'
outlookmailitem.Body = sheet1.Cells(56, 3)
myAttachments.Add (attachment)
outlookmailitem.Display
outlookmailitem.Send
address = ""
x = x + 1
Loop
Set outlookapp = Nothing
Set outlookmailitem = Nothing
End Sub
'''
question from:
https://stackoverflow.com/questions/65642597/server-execution-failed-vba-outlook-email-automation-failed 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…