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:
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