I am using this code, which works fine, to email a worksheet from within an Excel VBA script...
-------------------------------------------------------------------------------------
Dim outlookApp As Object
Dim outlookMail As Object
Dim wbTemp As Workbook
Dim strFileName As String
Set outlookApp = CreateObject("Outlook.Application")
Set outlookMail = outlookApp.CreateItem(0)
With outlookMail
.To = "test@yourco.com"
.Subject = "Requested Spreadsheet"
.BodyFormat = 2
.HTMLBody = "Good morning!,<p>Attached is the spreadsheet you requested."
.Attachments.Add strFileName
.Importance = olImportanceHigh
.Send
End With
Set outlookMail = Nothing
Set outlookApp = Nothing
Kill strFileName
-----------------------------------------------------------------------------------------------
As noted, the script works fine and runs to completion, but does generate an Outlook 2007 error message as shown in the attached file. I suspect this has to do with the version of Outlook being 2007, as I do not get the error when test-running the code on a machine with Outlook 2013. If any of you know how to adapt this code so as to eliminate the error, please post!
Which version of Excel are you using and which version of Excel was used to create the workbook you want to attach a sheet from?
Glenn Stearns
ASKER
Norie...
The version of Office on the machine running the code is Office 2007. Spreadsheet and VBA are in that version of Excel. The VBA script only runs in Excel 2007. It is extensive and has several commands in it which are not compatible with Excel 2013. I have tested the email part of the script in a similar situation on another machine running Office 2013 and I do not get the error. From what I'm reading online, this is likely an Outlook 2007 error and not an Excel VBA problem - something having to do with conflicting add-ins to Outlook 2007, which is what I am checking now. I believe this because I get the error when starting Outlook 2007 alone from the start menu.
Does it work then?