- Joined
- May 1, 2013
- Messages
- 22
- Reaction score
- 0
Hello,
 
I am familiar with VBA in Excel but I am very new with VBA in Outlook. As a result, I have been stumbling over myself trying to figure out how everything works. What I am trying to accomplish is for a category to be marked on a mail message once that message has been marked complete. I have [semi-] working code for accomplishing this within my personal mailbox but I need it to work in a second mailbox (within the same profile) exclusively.
 
I am running into several issues with the code below:
 
1) As far as I can tell so far, there is no way to disable events in Outlook VBA and this results in this code running more than once--any tips would be appreciated.
 
2) Maybe I am overlooking something obvious but I think that when something is marked complete, Item.FlagIcon should equal olFlagComplete, which is 1. However, in my testing, when I mark a message complete it shows that Item.FlagIcon = 0 and I really can't imagine why.
 
3) I'm probably missing a key search term that would allow me to find this one myself but I can't figure out how to get this to run in the second mailbox that I mentioned, only in my own personal mailbox (I have tried using the email address for that mailbox where I currently have "my email address" in this code). Once again, any input would be appreciated!
 
	
	
	
		
 
Thanks in advance for the help!
				
			I am familiar with VBA in Excel but I am very new with VBA in Outlook. As a result, I have been stumbling over myself trying to figure out how everything works. What I am trying to accomplish is for a category to be marked on a mail message once that message has been marked complete. I have [semi-] working code for accomplishing this within my personal mailbox but I need it to work in a second mailbox (within the same profile) exclusively.
I am running into several issues with the code below:
1) As far as I can tell so far, there is no way to disable events in Outlook VBA and this results in this code running more than once--any tips would be appreciated.
2) Maybe I am overlooking something obvious but I think that when something is marked complete, Item.FlagIcon should equal olFlagComplete, which is 1. However, in my testing, when I mark a message complete it shows that Item.FlagIcon = 0 and I really can't imagine why.
3) I'm probably missing a key search term that would allow me to find this one myself but I can't figure out how to get this to run in the second mailbox that I mentioned, only in my own personal mailbox (I have tried using the email address for that mailbox where I currently have "my email address" in this code). Once again, any input would be appreciated!
		Code:
	
	Option Explicit
Public WithEvents OlItems As Outlook.Items
 
Public Sub Initialize_handler()
 
    Set OlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
 
End Sub
 
 
Sub OlItems_ItemChange(ByVal Item As Object)
 
Dim myNS As Outlook.NameSpace
 
Set myNS = GetNamespace("MAPI")
 
If myNS.GetDefaultFolder(olFolderInbox).Parent = "My email address" Then
    If Item.FlagIcon = 0 Then
            With Item
                .Categories = ""
                .Categories = "Some Category"
                .Save
            End With
    End If
End If
End SubThanks in advance for the help!
