send email macro with Outlook running

D

DaveH

I have a small macro that runs in Excel that will attach a file and emails
the attachment. Runs fine when Outlook is not running, but I have problems
when Outlook is already running. (runtime error ) and excel complains as
well.
Code looks like this:
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Set NSpace = OutlookApp.GetNamespace("MAPI")
OutlookMail.To = MailArchiveAddress 'EmailID
OutlookMail.Subject = " File Upload from: " & Name
OutlookMail.Body = "Calibration UpLoad File"
OutlookMail.Attachments.Add MailAttach ' attachment filename
OutlookMail.Display
set OutlookMail = Nothing
set OutlookApp = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top