×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Outlook in Task Scheduler

Outlook in Task Scheduler

Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

All variablisin VBS are variant, no "As", so only:
Dim myOutlook

combo

RE: Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

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

combo

RE: Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

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.

RE: Outlook in Task Scheduler

According to this discussion the code in outlook has to be in ThisOutlookSession class module.

combo

RE: Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

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

RE: Outlook in Task Scheduler

Try myOutlook.ThisOutlookSession.SendNewestFiles instead.
The /m switch is followed by emailname, not macro name, according to ms switch descriptions.
If myOutlook.SendNewestFiles 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

RE: Outlook in Task Scheduler

(OP)
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: https://support.office.com/en-us/article/command-l...

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.

RE: Outlook in Task Scheduler

/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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close