Outlook 2007 Error in Excel VBA Script

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)


Set wbTemp = ActiveWorkbook

wbTemp.SaveAs "C:\Temp\" & wbTemp.Sheets(1).Name & ".xlsx", xlOpenXMLWorkbook

strFileName = wbTemp.FullName

wbTemp.Close False

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


Glenn StearnsAnalystAsked:
Who is Participating?
Bill PrewCommented:
Searching for the title of your error box "ADX Loader" also yields some results you might look at.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
What if you replace the line .Importance = olImportanceHigh with .Importance = 2.
Does it work then?
Glenn StearnsAnalystAuthor Commented:

No - same error occurs with your recommended change.


Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Sorry! No idea.
See if this link gives you an idea.
NorieVBA ExpertCommented:
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 StearnsAnalystAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.