Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2019, 07:10 AM
johnc83 johnc83 is offline Outlook 2013 - Sending email when closed Windows 7 64bit Outlook 2013 - Sending email when closed Office 2003
Novice
Outlook 2013 - Sending email when closed
 
Join Date: Jul 2015
Posts: 6
johnc83 is on a distinguished road
Default Outlook 2013 - Sending email when closed

Hi, I have a task-scheduler spreadsheet with VBA that edits and the calls a wscript .vbs file. It all works smoothly right up until the Outbox.

If I have Outlook open at the time of the spreadsheet running, I get an error of this.

ActiveX component can't create object: 'Outlook.Application'
Code: 800A01AD

If I have Outlook closed at the time of the scheduled spreadsheet, then no error but the e-mail sits in the Outbox until Outlook is opened and then is sent almost immediately.



I could schedule Outlook to open and close throughout the day when these spreadsheets are running but I'd rather it just worked when Outlook is open all the time.

Here is the .vbs code
Code:
Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Recipients.Add ("john.smith@gmail.com")
objMailItem.Display
objMailItem.Subject = "Midnight Tank Stock Report"
objMailItem.Body = "Here is my body"
objMailItem.Send
Set objMailItem = nothing
Reply With Quote
  #2  
Old 08-13-2019, 09:05 PM
gmayor's Avatar
gmayor gmayor is offline Outlook 2013 - Sending email when closed Windows 10 Outlook 2013 - Sending email when closed Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you modify your code to call the function at Test if Outlook is open and open Outlook with VBA then Outlook should always be opened correctly regardless of whether it is running or not.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-15-2019, 03:16 AM
johnc83 johnc83 is offline Outlook 2013 - Sending email when closed Windows 7 64bit Outlook 2013 - Sending email when closed Office 2003
Novice
Outlook 2013 - Sending email when closed
 
Join Date: Jul 2015
Posts: 6
johnc83 is on a distinguished road
Default

Hi, thanks for the reply. I've managed to sort now. It appears that running the scheduled task with the 'Higher' privileges* is effectively running it as Administrator. If I make sure Outlook is started as Administrator then the Excel spreadsheet can communicate fine with it.

*the reason I need higher privileges ticked is because if my RDP session locks (which it will do after 5 mins automatically) then the scheduled task just won't run
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expanding "CC" field when sending an email in Outlook 2013 Dougmeister Outlook 0 11-29-2017 06:57 AM
Outlook 2013 - Sending email when closed Outlook not sending email grjbyfleet Outlook 1 07-30-2016 11:52 AM
outlook.com account in Outlook 2007 freezes at 93% sending/receiving email ink8 Outlook 0 10-10-2012 12:19 PM
Outlook not sending body of email sbertram Outlook 0 08-30-2012 11:50 AM
Receiving but not sending email in outlook? babylikesburgh Outlook 2 12-05-2010 06:29 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft