Problem using 2010 Macro in excel 2013

liamnimeh

New Member
Joined
Jan 27, 2015
Messages
2
So I have recently updated from office 2010 to office 2013. I previously had a macro which send out personalised emails to a list of recipients and attached a series of files. This worked perfectly in 2010 but is throwing up an error in 2013, looking for some advice with this.

Code:
Sub EmailMacro()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim Temp As String
    
    Temp = Range("OutTemp")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItemFromTemplate("C:\Users\labunimeh\Documents\Client Work\FS\Outlook Template KSN v03.msg")


    With OutMail
        .SentOnBehalfOfName = Range("E_From")
        .To = Range("MailTo")
        .CC = Range("MailCC")
        '.BCC = Range("MailBCC)
        .Subject = Range("Subject")
        '.HTMLBody = "<body>" & Range("BodyText") & "</body>" & OutMail.HTMLBody
        .Importance = Range("Importance")
        If Range("Attach1") = "Yes" Then
        .Attachments.Add (Range("Attachfile1"))
        End If
        On Error Resume Next
        If Range("attach2") = "Yes" Then
        .Attachments.Add (Range("AttachFile2"))
        End If
        On Error Resume Next
        If Range("attach3") = "Yes" Then
        .Attachments.Add (Range("AttachFile3"))
        End If
        On Error Resume Next
        If Range("attach4") = "Yes" Then
        .Attachments.Add (Range("AttachFile4"))
        End If
        On Error Resume Next
        If Range("send") = "Send" Then
        .Send
        ElseIf Range("send") = "Save" Then
        .Save
        Else
        .Display
        End If
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Above is the VBA code used. The error being given is as follows "Method '.SentOnBehalfOfName' of object '_MailItem' failed". I can't for the life of me understand why this would not work in 2013, need to send out emails asap so any advice on the matter would be much appreciated!!!

Thanks
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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