Anyway, it's not really important what language this is written in. Wanted to see if any of you have written this in VBScript or help point me in the right direction.
Thanks,
Jamie
VB ScriptOutlook
Last Comment
David Lee
8/22/2022 - Mon
David Lee
Hi, Jamie.
Does the rule need to do something specific, or do you just want to see how to create rule this way?
jamorlando
ASKER
The rule would take a message sent to user X and move the message to folder Y.
The folder path is probably not valid. A folder path in Outlook is essentially the same as a folder path in the file system. The one difference being that Outlook folder paths do not include a drive letter. The path to a folder is a list of all the folders from the root to the target folder with each folder name separated from the preceding folder name by a backslash (i.e. \). Consider the following folder structure:
The path to "Inbox" is "Mailbox - Doe, John\Inbox".
The path to "Reviews" is "Personal Folders\Marketing\Reviews".
The path to "Project 1" is "Personal Folders\Projects\Project 1".
jamorlando
ASKER
I tried:
Set .Folder = OpenOutlookFolder("Mailbox - SPAM\Inbox\aaa")
and
Set .Folder = OpenOutlookFolder("\\Mailbox - SPAM\Inbox\aaa")
Getting the same type mismatch error. I've already created the folder, and the permissions are fine.
Any ideas?
David Lee
Is the folder visible in Outlook's navigation pane (i.e. the folder list)? Is this a folder in your mailbox?
Set .Folder = olkSes.GetDefaultFolder(6).Folders("aaa")
Worked!
Thanks so much!
David Lee
You're welcome. Glad I could help.
jamorlando
ASKER
One more question if you don't mind:
This script worked perfectly when I ran it locally. However when I go to run it remotely via the PSExec.exe utility, I get the following error on the line:
Set olkApp = GetObject(,"Outlook.Application")
It says:
C:\Scripts\CreateRule.vbs(4, 1) Microsoft VBScript runtime error: ActiveX component can't create object: 'GetObject'
I notice that the GetObject function takes 2 parameters and the first one is blank. Is there something that should go in there (remote server name?) to make this work remotely?
When called with the syntax I've used GetObject retrieves the running instance of Outlook. The first parameter can be a path to a file. It is not a machine name. Add the command
On Error Resume Next
between lines 3 and 4.
jamorlando
ASKER
Sorry to keep bothering you..
On Error Resume Next
makes the script run with no errors, however the rule never gets created.
When you say, the first parameter can be a path to a file, should I set up the GetObject line like:
Set olkApp = GetObject("C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE","Outlook.Application")
Any ideas?
David Lee
I doubt that'll make any difference, but there's no harm in trying.
Does the rule need to do something specific, or do you just want to see how to create rule this way?