A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 11th 09, 10:16 AM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default Scheduled Task Fails running Code to send Outlook Mail from Excel.

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://social.answers.microsoft.com/...?prof=required

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.
Ads
  #2  
Old November 11th 09, 03:19 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Scheduled Task Fails running Code to send Outlook Mail from Excel.

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().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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://social.answers.microsoft.com/...?prof=required

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.


  #3  
Old November 11th 09, 05:02 PM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default 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!

"Ken Slovak - [MVP - Outlook]" wrote:

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().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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://social.answers.microsoft.com/...?prof=required

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.


.

  #4  
Old November 12th 09, 04:07 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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!


  #5  
Old November 12th 09, 06:09 PM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default 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.



"Ken Slovak - [MVP - Outlook]" wrote:

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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!


.

  #6  
Old November 12th 09, 06:38 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP][_4_]
external usenet poster
 
Posts: 552
Default 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, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Old Man River" wrote in message
...
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.



"Ken Slovak - [MVP - Outlook]" wrote:

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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!


.



  #7  
Old November 12th 09, 07:12 PM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default 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.

"Ken Slovak - [MVP - Outlook]" wrote:

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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!


.

  #8  
Old November 13th 09, 01:07 AM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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.


  #9  
Old November 13th 09, 12:54 PM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default 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:

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, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Old Man River" wrote in message
...
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.



"Ken Slovak - [MVP - Outlook]" wrote:

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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!

.



.

  #10  
Old November 13th 09, 12:56 PM posted to microsoft.public.outlook.program_vba
Old Man River
external usenet poster
 
Posts: 19
Default 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.

"Ken Slovak - [MVP - Outlook]" wrote:

Sue gave you the answer. I made a mistake in not remembering that your
scenario is not supported. She's absolutely correct.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Old Man River" wrote in message
...
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.


.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scheduled Task Doesn't work with Outlook 2007 CaptainBly Outlook and VBA 1 October 27th 09 03:35 PM
VBA and Scheduled task in Outlook small caps Outlook - General Queries 1 July 11th 09 05:37 PM
Send Update Fails to External E-Mail Addresses Nostradamus2 Outlook - Calandaring 0 February 18th 09 07:34 PM
Outlook within Excel, get return code to know if user pressed SEND gary Outlook and VBA 3 July 20th 07 08:56 PM
Outlook 2007 Mail fails to Send, stuck in Outbox Ellie Outlook - General Queries 0 February 15th 07 04:26 PM


All times are GMT +1. The time now is 09:28 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.