picklechips
New Member
- Joined
- Jun 22, 2018
- Messages
- 21
Hi all,
I had been running a macro for the last few months and everything worked perfectly. Now I get the error "Invalid Procedure Call or Argument" at the .send vba code. Nothing changed, I don't know why it just started happening..
The macro uses a list of email addresses from an excel file, where it creates an email, bcc's the first 100 addresses, attaches a PDF and copies a Powerpoint file into the email body then sends the email. Then it repeats with next 100 addresses until it goes through all addresses.
Code is below. Thanks in advance!
Pickles
I had been running a macro for the last few months and everything worked perfectly. Now I get the error "Invalid Procedure Call or Argument" at the .send vba code. Nothing changed, I don't know why it just started happening..
The macro uses a list of email addresses from an excel file, where it creates an email, bcc's the first 100 addresses, attaches a PDF and copies a Powerpoint file into the email body then sends the email. Then it repeats with next 100 addresses until it goes through all addresses.
Code is below. Thanks in advance!
Pickles
Code:
Option Explicit
Sub Brokeremail1()
Dim TempFile As String
Dim OutApp As Object
Dim OutMail As Object
Dim EmailTo As String
Dim Ratesheetpdf As Variant
Dim subj As String
Dim body As String
Dim LastRw As Long
Dim i As Integer
Dim wb As Workbook
Set wb = ThisWorkbook
On Error GoTo ErrorHandler
'Ratesheet pdf attachment
MsgBox ("SELECT RATESHEET PDF - EMAIL ATTACHMENT")
Ratesheetpdf = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
'ppt slide attachment
MsgBox ("SELECT POWERPOINT FILE - EMAIL BODY")
Dim strFileName As String
strFileName = Application.GetOpenFilename( _
FileFilter:="PowerPoint Files (*.pptx), *.pptx", _
Title:="Open", _
ButtonText:="Open")
If strFileName = "False" Then Exit Sub
Dim pptApp As Object
Dim pptPres As Object
Dim pptSlide As Object
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPres = pptApp.Presentations.Open(strFileName)
Set pptSlide = pptPres.Slides(1)
Set OutApp = CreateObject("Outlook.Application")
'Get the text that will go on the email subject
subj = Sheets(1).Range("f2")
wb.Activate
'Assign the file name for the temporary image file of the PowerPoint slide
TempFile = "temp.jpg"
'Export slide from PowerPoint presentation to temporary file
pptSlide.Export Filename:=Environ("temp") & "\" & TempFile, FilterName:="JPG"
'Create email loop
LastRw = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LastRw Step 100
EmailTo = Join(Application.Transpose(Sheets(1).Range("A" & i & ":A" & WorksheetFunction.Min(i + 99, LastRw)).Value), ";")
Set OutMail = OutApp.CreateItem(0)
Set OutMail.SendUsingAccount = Session.Accounts.Item(2)
With OutMail
.Display
.To = ""
.CC = ""
.BCC = EmailTo
.Subject = subj
.body = ""
.SendUsingAccount = OutApp.Session.Accounts.Item(2)
.Attachments.Add Environ("temp") & "\" & TempFile
.HTMLBody = "<img src=""cid:" & TempFile & """ width=""150%"">"
.HTMLBody = .HTMLBody & "<p>If you wish to unsubscribe to this e-mail please respond with the subject Unsubscribe.</p>"
.Attachments.Add Ratesheetpdf
.Send
End With
Next i
On Error GoTo 0
'Delete the temporary image file of the PowerPoint slide
Kill Environ("temp") & "\" & TempFile
pptPres.Close
pptApp.Quit
Set pptApp = Nothing
Set pptPres = Nothing
Set pptSlide = Nothing
Set OutMail = Nothing
Set OutApp = Nothing
Exit Sub
ErrorHandler:
pptPres.Close
pptApp.Quit
MsgBox Err.Description & Err.Number & Err.Source & Err.HelpFile & Err.HelpContext
OutMail.Close 1
End Sub