ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   send email macro with Outlook running (https://www.excelbanter.com/excel-programming/411387-send-email-macro-outlook-running.html)

Daveh

send email macro with Outlook running
 
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


All times are GMT +1. The time now is 03:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com