Scheduled Task Fails running Code to send Outlook Mail from Excel.

Status
Not open for further replies.
O

Old Man River

I am trying to run this subroutine from an Excel Macro in a Scheduled job.

Private Sub SendMessage()

Dim OutApp As Object

Dim OutMail As Object

'ToStr, Subject and strBody are globals in the Excel VB Module.

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)

With OutMail

> To = ToStr

> CC = "xxx@yyy" 'Real address obscured here.

> BCC = ""

> Subject = Subject

> Body = strbody

> Send

End With

End Sub

It works perfectly when triggered by opening the spreadsheet which has an

auto run macro which invokes the code. Either manually from Excel or by

running the Command Line "C:\Program Files\Microsoft

Office\Office12\Excel.exe" /r "C:\Users\Alan\Documents\HSC\Fence Check\Fence

Check Auto Run.xlsm"

Normally the scheduled task that runs the same code (there is a bit more to

it) runs perfectly but when it hits the above it is failing and as a result

screwing up the scheduled job which then fails to complete and subsequently

will not run until after a reboot and re-registering the task.

This is a follow on from a previous thread viz:

http://answers.microsoft.com/en-us/...nal-data/96994b77-d690-4403-8b51-4e1d0ae998e1

Can anybody help or suggest a workaround. P.S. I always have Outlook Open on

my Desktop and I hate having to late bind the Objects in this code.

---Also posted in Office Developer Automation - but seems a pretty inactive

forum.
 
I have no idea how that other link relates to this but just use GetObject()

to see if Outlook is running, if not use CreateObject().

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Thanks Ken but as I understand it Outlook is a single instance programme so

both GetObject() and CreateObject() are equivalent. Thing is it works

perfectly when manually triggered but fails in a scheduled task!
 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Did you try what I suggested? If not try it and see if it helps.

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Thanks Ken

Put some debug code in and am getting the error

"Error # 70 was generated by VBAProjectPermission denied" if I use

CreateObject

and

"Error # -2147221020 was generated by VBAProjectAutomation error

Invalid syntax " if I use GetObject.

But thanks anyway. I'll start a new post to see if anyone can tell me what

this error means.

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

PMFJI, but it may mean that what you're trying to do isn't possible, given

that automating Outlook from a scheduled task is not a supported scenario.

Sue Mosher
 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Tried again after checking the GetObject syntax and adding in a comma and got:

Error # 429 was generated by VBAProjectActiveX component can't create object.

Different Error message but does confirm that Create and Get Object are

equivelent for OutLook.

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Sue gave you the answer. I made a mistake in not remembering that your

scenario is not supported. She's absolutely correct.

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Feel free to jump whenever you want!

Thank's I was begining to think that it was a security issue. So I'll have

to skin this cat a different way (Can't accept impossible)!

I'm thinking (hoping) pick up on a reminder event in Outlook and trigger the

Excel from there. Just need to have a scheduled job that wakes the machine so

Outlook triggers the reminder if I'm away for a while.

"Sue Mosher [MVP]" wrote:

 
Re: Scheduled Task Fails running Code to send Outlook Mail from Ex

Many Thanks Ken for your interest - see my post in response to Sue's.

 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Running Outlook as Scheduled task Outlook VBA and Custom Forms 1
C Scheduled Task Doesn't work with Outlook 2007 Outlook VBA and Custom Forms 1
Fozzie Bear Shared Calendar For Scheduled Tasks Using Outlook.com accounts in Outlook 3
V Scheduled backup of imap account Using Outlook 7
T Scheduled footer change Using Outlook 2
S Scheduled backup for BCM Database Tool BCM (Business Contact Manager) 1
C How do you add an attendee to a already scheduled meeting? Using Outlook 3
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
D Copy Appointment Body to Task Body Outlook VBA and Custom Forms 0
K Daily Task List Minimized Cannot Display Using Outlook 5
wayneame Changing the Form Used by Existing Task Items in a Folder Outlook VBA and Custom Forms 4
S Outlook 2016 Understand and customize prepended behavior of recurring task Using Outlook 0
B Outlook 365 Populate Outlook Task UDFs from a UDF text string Outlook VBA and Custom Forms 2
K Multiple copies of task being created Using Outlook 2
P Short Date Format when typing in a task Using Outlook 2
C Outlook 2013 Task Recurrence - Third Friday After the Second Tuesday Using Outlook 2
P Task display now leaves little room for notes Using Outlook 10
C-S-R How to clear an Outlook (To Do) Task Flag? Using Outlook 8
G Event when creating task from mailitem Outlook VBA and Custom Forms 2
P Changing the font that the task view shows Using Outlook 5
D How To Combine Share Task Folders in just one Folder Using Outlook 0
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
G Arggh, weakness of reminder for every Task recurrence Using Outlook 0
P Can't paste an image into a task Using Outlook 3
F Validation on custom task form after task acceptance Outlook VBA and Custom Forms 1
J Office 365 erased all of my task views Using Outlook 3
T Report For Task Recurrance Outlook VBA and Custom Forms 4
E Can't accept or decline task (no button appears) Using Outlook 2
Z VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
Z Task Filter Not Working When I add too many criteria Using Outlook 0
X If you change expiration date of repeated task it dupplicates Using Outlook 1
Z How to show concatenated categories in list task view? Using Outlook 2
Z VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
E To convert imported data to custom fields in Task list Outlook VBA and Custom Forms 1
I Help with dates in task list. Using Outlook 5
Y Outlook Task View - Table Format - Customize Reminder Time to Drop-Down Selection Using Outlook 2
M Daily Task List Minimized Cannot Display Using Outlook 2
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4
P Add a contact to the New Task in Outlook 2016 Using Outlook 2
S Codes for "Mark Complete" the task Outlook VBA and Custom Forms 2
W Deleting Sent Task Email, Deletes the task from my list Using Outlook 1
K Task priority modification Using Outlook 4
F Search folder for tasks in all task folders Using Outlook 1
JohnViuf Export task list view settings to other pc Outlook VBA and Custom Forms 16
V Changing default date for task follow-up buttons Using Outlook 2
K outlook workflow: automated task generation Outlook VBA and Custom Forms 4
U HTML Task Alternate Home Page View Control Using Outlook 3
F How to assign a task to a public task folder? Using Outlook 1
J Marketing task MS BCM BCM (Business Contact Manager) 10
copperberry How to view all tasks across task folders Using Outlook 3

Similar threads

Back
Top