?
Solved

Script VBA to assign a value to a user-define column in Outlook 2007 Inbox

Posted on 2011-10-21
22
Medium Priority
?
378 Views
Last Modified: 2012-08-14
We want to create a Rules Wizard so when an email that we received is from example@domain.com, the user-defined column 'Type' in the Outlook 2007 Inbox will have the value "SUPPORT"

The Rules Wizard part we have it, we are looking for the VBA portion that will save the value to the column
0
Comment
Question by:rayluvs
  • 13
  • 9
22 Comments
 
LVL 72

Expert Comment

by:Qlemo
ID: 37016542
Private Sub SetTypeProperty(ByVal Item As MailItem)
  Call item.UserProperties.Add("Type", "SUPPORT")
End Sub

Open in new window

0
 

Author Comment

by:rayluvs
ID: 37019288
We have worked with Rules Wizard and have created various, but not with script.

Hera is what we did: we placed your script within the MODULE in VBA but when creating the rules, it pops up a window 'Select Script' but is empty.

Please advice
0
 
LVL 72

Assisted Solution

by:Qlemo
Qlemo earned 2000 total points
ID: 37019478
Sorry. The procedure may not be defined private, and the Rule Wizard doesn't allow for the ByVal keyword, so the code is
Sub SetTypeProperty(Item As MailItem)
  Call Item.UserProperties.Add("Type", "SUPPORT")
End Sub

Open in new window

It doesn't matter whether you put it into ThisOutlookSession or a different module.
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 

Author Comment

by:rayluvs
ID: 37020201
Tried it, and gave an error "Run-rime error '13'" (see pic)
ErrorRules.jpg
0
 
LVL 72

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 37021148
I'm too stupid to understand my own code, and do it right. Sigh. Last try:
Sub SetTypeProperty(Item As MailItem)
  Item.UserProperties.Add("Type", olText) = "SUPPORT"
End Sub

Open in new window

0
 

Author Comment

by:rayluvs
ID: 37021265
Hey buddy, dont say that! You guys in EE have been excellent with!!!

Will try & let you know

Thanx
0
 

Author Comment

by:rayluvs
ID: 37021875
Didn't work.

Also tried "Run this rule now on messages already in Inbox" and it didn't work.

0
 

Author Comment

by:rayluvs
ID: 37021901
We tested the Rules we created by changing it to assign a Category and it works.  But with the script it doesn't.  We place stop at "Sub SetTypeProperty(Item As MailItem)" to see it run line by line it does goes line by line but it doesn't fill the "Type" column.
0
 
LVL 72

Assisted Solution

by:Qlemo
Qlemo earned 2000 total points
ID: 37022959
How do you display the "Type" column?
For test, select one mail (but do not open it) which should have the Type column changed already, open VBA Editor (Alt-F11), open Direct  Window (Ctrl-G), and type
  ? Outlook.ActiveExplorer.Selection.Item(1).UserProperties("Type")
That should display SUPPORT then.
We might have to add an Item.Save to the Sub to commit the change.
0
 

Author Comment

by:rayluvs
ID: 37023407
Ok, tested it.  What I did was change the Type contents to "EE", then Alt-F11, CTRL-G and the "?..." and it does display the value I enter in the Type column.  I can change the value and run your test steps and it displays the changed contents.
0
 

Author Comment

by:rayluvs
ID: 37023412
I placed the Item.Save and still no show
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37023460
>> What I did was change the Type contents to "EE",
How did you do that?
0
 

Author Comment

by:rayluvs
ID: 37023497
Ok What i did change the rule to sava SUPPORT In type column when the email received has TESTEE in the subject.

When sent, the rule didn't save SUPPORT in the type column; hence, Type is empty.  So I went in the Type column and change he value to "EE" (this is done by hanging the view to permit changes directly from user in inbox).  I can change the Type contents and user your yet steps and it does display the contents.
0
 

Author Comment

by:rayluvs
ID: 37023505
I meant "when received my email, the rule didn't save SUPPORT in the type column"
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37023954
So the value is changed successfully if you do it manually by any means, but not with the rule?
0
 

Author Comment

by:rayluvs
ID: 37024267
The value is not changed.  What i mean is that the test instruction:

    "? Outlook.ActiveExplorer.Selection.Item(1).UserProperties("Type")"

Works after i manually change the "Type" contents.  The Rules worked perfectly because I see via the "Stop" that the control does go thru the VBA lines.  However, the value "SUPPORT" doesn't get saved in the received email.

I place Item.Save right before the END, is that correct?
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37024944
Yes. Let me test again, with the complete workflow needed. Maybe I have overlooked something.
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37025068
Works fine for me. I added the User Column Type to my view in OL2010, created a rule triggering the VBA code
Sub SetTypeProperty(Item As MailItem)
  Item.UserProperties.Add("Type", olText) = "SUPPORT"
  Item.Save
End Sub

Open in new window

and see the Type column filled with SUPPORT in my view. OL2007 or OL2010 do not differ in that regard (and OL2003 works the same, too).
0
 

Author Comment

by:rayluvs
ID: 37025225
Strange ... it doesn't on mine& its ol2007.  But will review on detail when back office.
0
 
LVL 72

Expert Comment

by:Qlemo
ID: 37025338
Make sure you are really seeing the User Property, not any other field called "Type". It might be part of a customized form, and hence need to be addressed differently.
0
 

Author Comment

by:rayluvs
ID: 37028256
It worked!! But I didn't nothin different.  Let me check again.
0
 

Author Closing Comment

by:rayluvs
ID: 37037790
Thanx
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
I came across an unsolved Outlook issue and here is my solution.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question