Link to home
Start Free TrialLog in
Avatar of glenn_r
glenn_r

asked on

How to import a rule (rwz) into outlook thru automated script

I have an outlook rule that i've exported to rwz file. The next step is deployment. I need to add this rule to over 500 client machines. Is it possible to write a script or something to do this?
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, glenn_r.

So long as you're using Outlook 2010 or later, we can create the rule via a script just as in the question that @Bill Prew linked to.  To do that, I'll need to know what the rule does.
Avatar of glenn_r
glenn_r

ASKER

why outlook 2010 and later will creating a rule via script not work with 2007?

my rule is pretty simple
when a subject contains a matching string run an external process
i've got this working via a rule
This should also be doable in Outlook 2007, just not any version earlier than that.  The reason for this is because in order to create a rule from VBA code in Outlook, Microsoft had to add that capability to the Outlook Object Model.  The Rules collection that allows this is not exposed to VBA until Outlook 2007.

~bp
Avatar of glenn_r

ASKER

ok last question is how do i deploy this script to client machines running outlook so it gets added to their 'thisoutlooksession' module? Need to push this out to 500 machines.
I couldn't remember for sure if it was Outlook 2007 or 2010 that first exposed rules, so I played it safe and said 2010.  

You wouldn't want to deploy VBA code to every computer.  that would be more painful than deploying the .rwz file and giving them all instructions on how to import it.  Instead, you'd want to write the code in VBscript since it runs outside of Outlook.  You could then either call that script from another script (e.g. a login script) or send everyone a link to the script.  Clicking that link would run the script and add the rule.
Avatar of glenn_r

ASKER

i tested and works with both 2007 and 2010

i need to deploy this silently
thinking via login script
u have a link to an example on what to run to get that script added to 'thisoutlooksession' module?
once i get that code i can handle rolling it out thru a login script
"u have a link to an example on what to run to get that script added to 'thisoutlooksession' module?"

That's not possible.  There is no way to add a macro to Outlook other than to do it manually (i.e. type it in or copy and paste).  That's what I was saying in my last comment: you don't want to deploy VBA code.  If the macro is ready (i.e. it creates the rule you want), then we need to convert the macro to VBscript.  I'll be glad to help you do that.  I just need the code.
Avatar of glenn_r

ASKER

confused
"no way to add a macro to Outlook"
"need to convert the macro to VBscript"

for clarification do we have 3 items here?
1) macro
2) vba
3) vbscript

simple rule

'Option Explicit
'
'Private WithEvents olInboxItems As Items
'
'Private Sub Application_Startup()
'  Dim objNS As NameSpace
'  Set objNS = Application.Session
'  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
'  Set objNS = Nothing
'End Sub
'
'Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
'
'  On Error Resume Next
'
'  Const searchString As String = "lockdown" ' put your search criteria here
'  Dim testPos As Integer
'
'  testPos = InStr(Item.Subject, searchString)
'
'  ' search string found run your ppt
'  If testPos > 0 Then
'    ' displays messagebox for now but replace the statement below with your ppt invokation
'    MsgBox (searchString & " found")
'  End If
'
'  Set Item = Nothing
'
'End Sub
'
glenn_r,

Let me see if I can clear up the confusion.  VBA is a programming language.  Microsoft Office macros are written in VBA.  The terms "macro" and "script" are synonymous in the context of writing some code in VBA to run inside of an Office application (e.g. Outlook, Word, Excel, etc.)  There is no automated way to add/create/install a macro in Outlook.  The only way to add macro code in Outlook is to do it manually.  By "manually", I mean open the VB editor in Outlook and either type in the code or copy and paste the code in.  In the context of what you want to accomplish, if you write the code in VBA, then you'll have to send the code and detailed instructions on how to add it to Outlook to everyone that's going to use it.  On receiving the code and the instructions, they will then have to

1.  Open Outlook
2.  Open the VB editor in Outlook
3.  Copy and paste the code into the VB editor
4.  Save the changes
5.  Close the editor
6.  Open Security
7.  Go to the section on Macro security
8.  change the default security settings to allow macros to run
9.  Run the macro they copied in on step #3

That's a lot of steps to perform and working through them all completely eliminates the point of the script, which is to make adding the rule easy.  You'd be better off sending them the rule file with instructions on how to import it, or sending them instructions on how to create the rule from scratch.

Fortunately, there's an alternative.  That is to write the code in VBscript, another programming language that is similar to VBA, but runs from outside of Office apps rather than from inside of them (as VBA does).  With VBscript there's no code to add/install in Outlook, so there's no need to send the users the code or instructions on how to add it to Outlook.  All you need to send them is a link.  Clicking the link will run the script and add the rule to Outlook.  As I mentioned, VBscript is like VBA, but it has some key differences which require changing the code.

Does that make things clearer?

The code you included in your last comment does not create a rule.  So, my question is, have you already written the VBA version of the code to add your rule?  If so, then post that code and I'll convert it to VBscript for you.  If you have not written the code, then I'll write the VBscript from scratch.  To do that, I need to know exactly what the rule does.
Avatar of glenn_r

ASKER

simple example - i posted sample code in the last response
when the keyword 'lockdown' is found in the email display a msgbox
show me a vbscript example for the above and i can take it from there
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of glenn_r

ASKER

Thanks for all your help
for deployment i ended up just copying out the otm file for outlook macros as i can control security and not have to fool around with adjusting GPO's etc.