VBA to assign category on calendar item does not work ?? why ??

  • Thread starter Thread starter PGT
  • Start date Start date
P

PGT

Below i wrote code to assign a categorie to a calendar item based on the word "vrij" in the subject
I got to automate a lot of words for a lot of people so this just the first keyword
I think this code should work.. but somehow it doesn
I use Outlook 2003 with macro security set to lowest level. The code is placed in "this outlook session

Any ideas why it doesnt work ?
===================================================

Dim WithEvents colRDVItems As Item

Private Sub Application_Startup(
Dim NS As Outlook.NameSpac
Set NS = Application.GetNamespace("MAPI"
Set colRDVItems = NS.GetDefaultFolder(olFolderCalendar).Item
Set NS = Nothin
End Su

Private Sub colRDVItems_ItemAdd(ByVal Item As Object

If Item.Class = olAppointment The
If InStr(LCase(Item.Subject), "vrij") > 1 The
AddCat Item, "Holiday
Item.Sav
End I
End I
End Su

Sub AddCat(itm, catName
arr = Split(itm.Categories, ","
If UBound(arr) >= 0 The
' item has categorie
For I = 0 To UBound(arr
If Trim(arr(I)) = catName The
' category already exists on ite
' no need to add i
Exit Su
End I
Nex
itm.Categories = itm.Categories & "," & catNam
Els
' item has no categorie
itm.Categories = catNam
End I
End Sub
 
Try the InStr() function with the correct arguments and see if the code
works. You need to either put a comma at the beginning of the function
arguments or put an explicit starting point:

If InStr(1, LCase(Item.Subject), "vrij") > 0 Then

If that doesn't help you need to step the code when the event handler fires
and see what's going on. That's if the code is running at all, that's not
clear from your post.
 
instr can be used this way giving it a startposition is not required. It seams to me this code is not running at all
if for example i put a msgbox allert inside colRDVItems_ItemAdd it doesnt popup, when i add a new item to my calendar. I strongly think this code is OK, but maybe the default VBA isnt running or ..??? can you try this code?? (note ol2003 requires low macro security for this to work)
 
The code may not be running, or if the subject starts with your test string
it will never go past the If tests. I prefer to use a starting index, but
with or without that if the index of where that string starts is 1 the If
test will fail unless you test for > 0.

Does any other VBA code run for you?
 
If you want the function to ignore lower/upper cases, use the start
parameter and vbTextCompare:

pos=Instr(1, Item.Subject, "vrij", vbTextCompare)

Are you sure, "vrij" doesn't start at the beginning of the Subject? If it
does, the function would return 1, and that is not > 1.

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 22 Dec 2009 06:46:41 -0800 schrieb PGT:
instr can be used this way giving it a startposition is not required. It
seams to me this code is not running at all.
if for example i put a msgbox allert inside colRDVItems_ItemAdd it doesnt
popup, when i add a new item to my calendar. I strongly think this code is
OK, but maybe the default VBA isnt running or ..??? can you try this code??
(note ol2003 requires low macro security for this to work).http://msgroups.net/microsoft.publi...category-on-calendar-item-does-not-work-why,2
 
yeah i got that >1 replaced by >0
i found it myself after the post

Now i notice sometimes this code works other times it seams this macro is not running, strange as it should run always
i restart outlook and then sometimes it works other times not, i'm not sure what is going on, its not the outlooksp
 
Back
Top