Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook in Task Scheduler

Status
Not open for further replies.

supportsvc

Technical User
Jan 24, 2018
249
US
I currently have this text.vbs

Code:
Dim myOutlook As Object
Set myOutlook = GetObject("Outlook.Application")
myOutlook.Application.Run "SendNewestFiles"
myOutlook.Application.Quit
Set myOutlook = Nothing

I am getting an error however
Line: 1
Char: 15
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error

I would like to run this in Windows Task Scheduler

If there is a better way to run the Macro in Outlook on a daily basis at a certain time, please share.
 
All variablisin VBS are variant, no "As", so only:
[tt]Dim myOutlook[/tt]

combo
 
Yes, still getting an error on Application.Run
Object doesn't support the property or method:
'Application.Run'

Code:
Dim myOutlook
Set myOutlook = CreateObject("Outlook.Application")
myOutlook.Application.Run "SendNewestFiles"
myOutlook.Application.Quit
Set myOutlook = Nothing

 
There is no Application.Run in outlook. Try, with Public SendNewestFiles in outlook vba:
[tt]myOutlook.SendNewestFiles[/tt]

combo
 
Same error

Object doesn't support the property or method:
'myOutlook.SendNewestFiles'

Code:
Set myOutlook = CreateObject("Outlook.Application")
myOutlook.SendNewestFiles
myOutlook.Quit
Set myOutlook = Nothing
 
You might have better luck in the VBScript group.

However, you might try creating a small VBA project with Outlook checked in References. This will give you access to Intellisense to see what methods you can call for Outlook.
 
According to this discussion the code in outlook has to be in ThisOutlookSession class module.

combo
 
Yes, the procedure is in ThisOutlookSession

It worked when using the Application_StartUp, but that creates it every time Outlook starts up
Need to run it once a day at specific time every day
 
As I understood the link, you need public procedure in ThisOutlookSession module. No need to create Application_StartUp event procedure, that is fired by outlook event. As they state, this is not documented, so no guarantee that it works.
Alternatively you can try to locate the whole procedure in VBScript and adapt it to automation. There are a lot of examples how to manipulate outlook from another office application (VBA), the code can be easily converted to VBScript.

combo
 
I haven't been able to find anything that works.
Errors one way or another ...

tried this too
Code:
Set myOutlook = CreateObject("Outlook.Application")
myOutlook.ThisOutlookSession.SendNewestFiles
myOutlook.Quit
Set myOutlook = Nothing

as well as the switch for Office 2016 in Task Scheduler

"C:\.... Outlook.exe" /m ThisOutlookSession.SendNewestFiles
 
Try [tt]myOutlook.ThisOutlookSession.SendNewestFiles[/tt] instead.
The /m switch is followed by emailname, not macro name, according to ms switch descriptions.
If [tt]myOutlook.SendNewestFiles[/tt] does not work, rather move the code from SendNewestFiles to VBScript, as I suggested in previous post. You may find help in this forum (transfer code from outlook to other vba host + automation, start new thread) and VBScript forum (VBA => VBScript code conversion).


combo
 
Thanks. I did both with myOutlook.
I'll have to try and copy the Outlook Procedure and save it as a VBScript (*.vbs) outside out Outlook.

Ah, I was using the /mmacroname found here:
I just realized I should NOT have a space
Note: Do not include a space between the switch and the macro name.

Still didn't work. Doesn't recognize the switch.


DOH! I missed this is vbA and not vbS forum. moved.
 
/mmacroname is the name of switch in word, will not work in outlook. Click the header to have proper application switches The name of the macro should follow the switch, it is not a part of switch name (i.e.: /mmacroname YourMacroName).
Simple macro copy may not work, adapt it to automation and VBS.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top