Outlook 2007 Error in Excel VBA Script

Glenn Stearns
Glenn Stearns used Ask the Experts™
on
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)

ActiveSheet.Copy

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

Thanks!

Glenn
Outlook-Error.JPG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
What if you replace the line .Importance = olImportanceHigh with .Importance = 2.
Does it work then?
Glenn StearnsAnalyst

Author

Commented:
Subodh...

No - same error occurs with your recommended change.

Thanks!

Glenn
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
Sorry! No idea.
See if this link gives you an idea.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Test your restores, not your backups...
Top Expert 2016
Commented:
Searching for the title of your error box "ADX Loader" also yields some results you might look at.


»bp
NorieAnalyst Assistant

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

Author

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial