Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

       How did you like this article? Please vote and let us know.          

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Shannal L. Thomas
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath

 

 
  Using VBscript to remove categories

Outlook Calendar: Problems exporting Categories to a Pocket PC, and A VBscript to fix it.

 

Overview: For Pocket PC users we’ve encountered problems exporting calendar entries with certain types of category keywords.  We’ve written a VB script and COM add-in to fix the problem.

 

In the course of migrating legacy calendar data into Exchange 2000, Sumatra adds a keyword as a category to all email and calendar objects.  Categiories allow Outlook users to identify new email and calendar entries, and gives Sumatra a simple way to gracefully back out of an Exchange data migration if something goes wrong. 

 

A few weeks after a successful data migration, the client contacted us to discuss some unusual calendar behavior.  Calendar entries on the Pocket PC that were tagged with the Sumatra migration keyword (which for the purposes of discussion is “mmconv102659080356Z”) were not being displayed properly.  Our research confirmed the Pocket PC calendar import via ActiveSync has problems with categories[1].

 

Since the category to support the migration was added under program control into all calendars, it was easy to programmatically remove it in all users’ calendars.  The customer wondered if this tool could be applied to remove all categories.  Although this helps the Pocket PC users, it penalizes the rest of the organization who use categories.


We know we aren’t the only people who’ve run into this problem
[2], so we’ve produced the following Visual Basic script for an individual Outlook user to remove any keyword which has been found to cause a problem from all messages and calendar entries.

 

Public sub  remove_keywords()
'
'Goes through the inbox folder and removes keywords
'
 Dim olInboxItems As Outlook.Items
 Dim olAppSession As Outlook.NameSpace
 Dim olInboxFolder As Outlook.MAPIFolder  'use MAPI to loop through folder
 Dim olCalendarFolder As Outlook.MAPIFolder  'use MAPI to loop through folder
 Dim olMessage As Object                  'items in calendar/inbox are messages

 Dim olInboxMessages As Object
 Dim strUserKeyword As String
 Dim messages_seen As Integer
 
 Set olAppSession = Application.Session
 Set olInboxFolder = olAppSession.GetDefaultFolder(olFolderInbox)
 
 strUserKeyword = InputBox("Enter the keyword to remove, or enter * to remove all keywords")
 
 Set olInboxMessages = olInboxFolder.Items
 messages_seen = inbox_loop(olInboxMessages, strUserKeyword)
' MsgBox "Changed " & messages_seen & " messages with keywords in the inbox"
 
 Set olCalendarFolder = olAppSession.GetDefaultFolder(olFolderCalendar)
 Set olInboxMessages = olCalendarFolder.Items
 messages_seen = inbox_loop(olInboxMessages, strUserKeyword)
 'MsgBox "Changed " & messages_seen & " messages with keywords in the inbox"
 
 Set olInboxItems = Nothing     'Cleanup and exit
 Set olInboxFolder = Nothing
 Set olCalendarFolder = Nothing
 Set olAppSession = Nothing

 

End  Sub

 

Public Function inbox_loop(olInboxMessages, strUserKeyword)
'
' loop through each message in the inbox and reset keywords
'
 Dim olMessage As Object
 Dim num_changed As Integer
    num_changed = 0
    For Each olMessage In olInboxMessages
       If olMessage.Categories = strUserKeyword Or _
          (strUserKeyword = "*" And Len(olMessage.Categories) > 0) Then
            olMessage.Categories = ""    ' Sets the categories to nothing
            olMessage.Save               ' Saves the message
            num_changed = num_changed + 1
       End If
   Next
   inbox_loop = num_changed
End Function

 

 

 

It prompts to allow a single user to remove a single category keyword or all keywords from their Calendar and Inbox data.  Please note the following restrictions:

·         The only works on the Inbox and the Calendar (not Tasks, Contacts, or other mail folders)

·         This has no “UNDO” function.  If you remove a category you don’t want removed you’ll need to add it manually

·          Because of the way Exchange works, if this user is guest at a meeting which the meeting owner has added a category tag to AND the meeting is updated, the category label will again be added

·         Visual Basic Scripts (VBA) in Outlook does have some restrictions:

o        Users can modify VBA code unless the project is password-protected.  (This can introduce support problems when users start to modify the code.)

o        There is no simple way to distribute Outlook VBA code to users. Outlook supports one VBA project at a time. The successful implementation of the VBA script depends on the users to open the Visual Basic Editor and import the modules. An alternative would be to distribute an entire project file to users, but that would mean that any previous modifications to a user's project would be lost.  If the user has existing code, they must export the code to one or more module files before loading this VBA project, or the current project will be over-written.  That said, you can send this script around to the users who experience problems with the Pocket PCs, along with these instructions how to implement the macro.

 

1.        Copy the script. 

2.        Go to Tools-Macro-Visual Basic Editor. 

3.        Insert-Module and Paste the script in, OR, if you’ve chosen to download the code stored in the file “module1.bas”, you can  File-Import File-Module1.bas

4.        Save it, give it a name, and execute from the Macro function

 

o        Users who import code modules written by others will receive a warning message unless they either sign the VBA project or lower their macro security level. This message annoys users, who might lower their macro security level.  We caution against this: It exposes users (and potentially your organization) to malicious VBScript embedded in messages.

o        XP Users who don’t have macro protection set properly will receive this message: The macros in this project are disabled….”  Refer to this footnote to change the macro security settings to medium[3].

 

Another distribution strategy if this Pocket PC – Category problem impacts many users in your organization is to use a COM add-in.  Sumatra has converted this VBA macro into a COM add in.  This add-in will work for Outlook 2000, 2002, and 2003.  This COM add-in is available on an unsupported basis from: http://www.sumatra.com

 

 


Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Pro Exchange. OutlookExchange.Com and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

© Copyright Pro Exchange, Inc., 2006