VBA - Invalid Procedure Call or Argument

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

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
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,217,307
Messages
6,135,746
Members
449,963
Latest member
palm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top