Need a VBA to change Category of all email in my inbox

M

Murphybp2

I am trying to create a process that allows me to only see new emails
when I want to process them. I am unable to work offline at work as
when I try to do this I am not able to even open my outlook. So I
have thought of an alternative.

I have created a rule that when any new mail comes in, the category
for that mail is set to "New Mail". I then have created a view of my
inbox that looks for only mail that does not contain this category.
What I want to do next, is to create a toolbar button that I will call
"Retrieve Mail", that when I click it, will find any email with the
category of "New Mail", and remove that category from the item. I
don't want to delete all the categories, in case someone has sent me a
mail with a category that I want to keep. I just want to find any
mail with the category of "New Mail", and remove it.

I am using Outlook 2003. Anyone that can share a VBA that does this
would be appreciated. Thanks.
 
G

Guest

Your solution seems unnecessarily complicated for the problem you're trying
to solve. If you need to quickly see items in your Inbox that are unread, or
have been delivered today, create a View or a Search Folder using the
appropriate filters.
 
M

Murphybp2

Your solution seems unnecessarily complicated for the problem you're trying
to solve. If you need to quickly see items in your Inbox that are unread, or
have been delivered today, create a View or a Search Folder using the
appropriate filters.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/







- Show quoted text -

Thank you for your response, but I think you may have missed the
point. If I were to create a view that showed me unread items, then
as I was processing items, new ones would keep popping in as they were
recieved, which is what I want to avoid. Same problem if I created a
view that showed everything that was delivered today. I'm trying to
duplicate the same process that would occur if I was able to work in
an offline mode using the "Send/Recieve" option. If I were able to
work ofline (which I am not), then when I would hit "Send/Receive" it
would send and receive everything at that point. Any new items
received would not show until I did the "Send/Receive" again. So I
want to duplicate this same type of process. If you have a better
solution for doing that, I'm all ears. But just creating views
doesn't accomplish that.
 
G

Guest

Okay, I understand. Then you are on the right track with your proposed VBA
solution. Just filter the Items collection for the Inbox using the Restrict
method on the Categories property. Loop through them and use the Replace
function to remove the "NewMail" category from the .Category property, which
will leave any existing categories untouched.
 
M

Murphybp2

Okay, I understand. Then you are on the right track with your proposed VBA
solution. Just filter the Items collection for the Inbox using the Restrict
method on the Categories property. Loop through them and use the Replace
function to remove the "NewMail" category from the .Category property, which
will leave any existing categories untouched.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/






- Show quoted text -

Thank you for your response. I don't know how to write VBA...only
copy and paste. Can you send me a sample of what you have recommended?
 
G

Guest

Okay, I'll bite. :) The macro below will loop through all e-mails in your
Inbox and remove the NewMail category from all messages.

Sub RemoveNewMailCategoryFromMessagesInFolder()
On Error GoTo RemoveNewMailCategoryFromMessagesInFolder_Error

Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objItem As Object
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objItems = objInbox.Items

For intX = 1 To objItems.Count
If InStr(1, objItems.Item(intX).Categories, "NewMail",
vbTextCompare) <> 0 Then
Set objItem = objItems(intX)
objItem.Categories = Replace(objItem.Categories, "NewMail,", "",
, , vbTextCompare)
objItem.Categories = Replace(objItem.Categories, "NewMail", "",
, , vbTextCompare)
objItem.Save
End If
Next

Set objNS = Nothing
Set objInbox = Nothing
Set objItems = Nothing
Set objItem = Nothing

On Error GoTo 0
Exit Sub

RemoveNewMailCategoryFromMessagesInFolder_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
RemoveNewMailCategoryFromMessagesInFolder of VBA Document ThisOutlookSession"
Resume Next
End Sub

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Murphybp2 said:
Okay, I understand. Then you are on the right track with your proposed VBA
solution. Just filter the Items collection for the Inbox using the Restrict
method on the Categories property. Loop through them and use the Replace
function to remove the "NewMail" category from the .Category property, which
will leave any existing categories untouched.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/



Murphybp2 said:
On Aug 13, 1:16 pm, Eric Legault [MVP - Outlook]
Your solution seems unnecessarily complicated for the problem you're trying
to solve. If you need to quickly see items in your Inbox that are unread, or
have been delivered today, create a View or a Search Folder using the
appropriate filters.
:
I am trying to create a process that allows me to only see new emails
when I want to process them. I am unable to work offline at work as
when I try to do this I am not able to even open my outlook. So I
have thought of an alternative.
I have created a rule that when any new mail comes in, the category
for that mail is set to "New Mail". I then have created a view of my
inbox that looks for only mail that does not contain this category.
What I want to do next, is to create a toolbar button that I will call
"Retrieve Mail", that when I click it, will find any email with the
category of "New Mail", and remove that category from the item. I
don't want to delete all the categories, in case someone has sent me a
mail with a category that I want to keep. I just want to find any
mail with the category of "New Mail", and remove it.
I am using Outlook 2003. Anyone that can share a VBA that does this
would be appreciated. Thanks.- Hide quoted text -
- Show quoted text -
Thank you for your response, but I think you may have missed the
point. If I were to create a view that showed me unread items, then
as I was processing items, new ones would keep popping in as they were
recieved, which is what I want to avoid. Same problem if I created a
view that showed everything that was delivered today. I'm trying to
duplicate the same process that would occur if I was able to work in
an offline mode using the "Send/Recieve" option. If I were able to
work ofline (which I am not), then when I would hit "Send/Receive" it
would send and receive everything at that point. Any new items
received would not show until I did the "Send/Receive" again. So I
want to duplicate this same type of process. If you have a better
solution for doing that, I'm all ears. But just creating views
doesn't accomplish that.- Hide quoted text -

- Show quoted text -

Thank you for your response. I don't know how to write VBA...only
copy and paste. Can you send me a sample of what you have recommended?
 
M

Murphybp2

Okay, I'll bite. :) The macro below will loop through all e-mails in your
Inbox and remove the NewMail category from all messages.

Sub RemoveNewMailCategoryFromMessagesInFolder()
On Error GoTo RemoveNewMailCategoryFromMessagesInFolder_Error

Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objItem As Object
Dim intX As Integer

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objItems = objInbox.Items

For intX = 1 To objItems.Count
If InStr(1, objItems.Item(intX).Categories, "NewMail",
vbTextCompare) <> 0 Then
Set objItem = objItems(intX)
objItem.Categories = Replace(objItem.Categories, "NewMail,", "",
, , vbTextCompare)
objItem.Categories = Replace(objItem.Categories, "NewMail", "",
, , vbTextCompare)
objItem.Save
End If
Next

Set objNS = Nothing
Set objInbox = Nothing
Set objItems = Nothing
Set objItem = Nothing

On Error GoTo 0
Exit Sub

RemoveNewMailCategoryFromMessagesInFolder_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
RemoveNewMailCategoryFromMessagesInFolder of VBA Document ThisOutlookSession"
Resume Next
End Sub

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/



Murphybp2 said:
Okay, I understand. Then you are on the right track with your proposed VBA
solution. Just filter the Items collection for the Inbox using the Restrict
method on the Categories property. Loop through them and use the Replace
function to remove the "NewMail" category from the .Category property, which
will leave any existing categories untouched.
--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/
:
On Aug 13, 1:16 pm, Eric Legault [MVP - Outlook]
Your solution seems unnecessarily complicated for the problem you're trying
to solve. If you need to quickly see items in your Inbox that are unread, or
have been delivered today, create a View or a Search Folder using the
appropriate filters.
--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/
:
I am trying to create a process that allows me to only see new emails
when I want to process them. I am unable to work offline at work as
when I try to do this I am not able to even open my outlook. So I
have thought of an alternative.
I have created a rule that when any new mail comes in, the category
for that mail is set to "New Mail". I then have created a view of my
inbox that looks for only mail that does not contain this category.
What I want to do next, is to create a toolbar button that I will call
"Retrieve Mail", that when I click it, will find any email with the
category of "New Mail", and remove that category from the item. I
don't want to delete all the categories, in case someone has sent me a
mail with a category that I want to keep. I just want to find any
mail with the category of "New Mail", and remove it.
I am using Outlook 2003. Anyone that can share a VBA that does this
would be appreciated. Thanks.- Hide quoted text -
- Show quoted text -
Thank you for your response, but I think you may have missed the
point. If I were to create a view that showed me unread items, then
as I was processing items, new ones would keep popping in as they were
recieved, which is what I want to avoid. Same problem if I created a
view that showed everything that was delivered today. I'm trying to
duplicate the same process that would occur if I was able to work in
an offline mode using the "Send/Recieve" option. If I were able to
work ofline (which I am not), then when I would hit "Send/Receive" it
would send and receive everything at that point. Any new items
received would not show until I did the "Send/Receive" again. So I
want to duplicate this same type of process. If you have a better
solution for doing that, I'm all ears. But just creating views
doesn't accomplish that.- Hide quoted text -
- Show quoted text -
Thank you for your response. I don't know how to write VBA...only
copy and paste. Can you send me a sample of what you have recommended?- Hide quoted text -

- Show quoted text -

Thanks. Much appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top