Excel auto email from Outlook going from Office '07->'16

frosen

New Member
Joined
Nov 28, 2017
Messages
1
Hi folks!

We've just updated from Windows 8/Office 2007 to Windows 10/Office 2016 at work. Some time ago I created a help file for invoice posting that had a built in auto email feature if certain conditions were met.

To my horror I now realize that the auto email that Excel sent through Outlook is no longer working with our new Excel/Outlook. The basic structure I use is from Ron de Bruin's site. Then I have added bits and pieces from other places. I'm not particularly good at this but was quite proud of my self that I managed to get it working good with the old systems. :)

When Excel is supposed to send the email in the background I now get this error code: "Run-time error '-2147417851 (80010105)': Method 'To' of object '_MailItem' failed".

I have googled this but to no avail... Does anyone have a clue on how I can update the code so it works in Excel/Outlook '16? I would really appreciate that!

The code I use:

Code:
Sub SendMail()    ActiveSheet.Unprotect
    Application.Calculation = xlManual
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Dim TempFilePath As String

    Set appOutlook = CreateObject("outlook.application")
    Set Message = appOutlook.CreateItem(olMailItem)
    
    With Message
        .Subject = "Potential positive Airframe P/L effect, MSN " & ActiveSheet.Range("H8")

        .HTMLBody = [Text that I can't insert in the "code format" with the forum tools]

        Call createJpg("INVOICE TOOL", "A1:R47", "DashboardFile")
        TempFilePath = Environ$("temp") & "\"
        .Attachments.Add TempFilePath & "DashboardFile.jpg", olByValue, 0

         .HTMLBody = .HTMLBody & [Screenshot of the excel file from a separate sub]

        .To = Sheets("Developer Help").Range("C33")
        .Cc = Sheets("Developer Help").Range("C34")
        .Send
    End With

    ActiveSheet.Protect
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    Application.Calculation = xlCalculationAutomatic
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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