A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA code to remove flag from all messages in Inbox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 23rd 06, 08:36 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 6
Default VBA code to remove flag from all messages in Inbox

I flag certain messages that I get with a certain color flag. I would
like to create a button that could remove that color flag from those
messages all at once. The end result would be the messages would no
longer have a flag. How would I accomplish this?

Ads
  #3  
Old May 2nd 06, 06:02 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 6
Default VBA code to remove flag from all messages in Inbox

I tried this code but I am getting an error for the line that states"If
Mail.FlagIcon=olYellowFlagIcon"

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = Item
If Mail.FlagIcon=olYellowFlagIcon
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #4  
Old May 3rd 06, 07:10 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default VBA code to remove flag from all messages in Inbox

Am 2 May 2006 09:02:06 -0700 schrieb :

Simply add a "then" at the end of that line. The syntax is: If ... Then ...

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.vbOffice.net --


I tried this code but I am getting an error for the line that states"If
Mail.FlagIcon=olYellowFlagIcon"

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = Item
If Mail.FlagIcon=olYellowFlagIcon
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #5  
Old May 4th 06, 02:08 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 6
Default VBA code to remove flag from all messages in Inbox

Thanks. I added that and tried it again. I don't get an error now,
but nothing seems to happen. I have 10 messages in my inbox with a
yellow flag. When I ran the macro, I expected it to clear the flag
from those items, but nothing happened. Here is the code I have. Do I
need to change anything else? I even tried selecting the messages
first, but that didn't help.

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = Item
If Mail.FlagIcon = olYellowFlagIcon Then
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #6  
Old May 4th 06, 08:21 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default VBA code to remove flag from all messages in Inbox

Am 3 May 2006 17:08:24 -0700 schrieb :

For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = Item


"Item" is not a declared variable. Replace it please by "obj".

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.vbOffice.net --


Thanks. I added that and tried it again. I don't get an error now,
but nothing seems to happen. I have 10 messages in my inbox with a
yellow flag. When I ran the macro, I expected it to clear the flag
from those items, but nothing happened. Here is the code I have. Do I
need to change anything else? I even tried selecting the messages
first, but that didn't help.

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = Item
If Mail.FlagIcon = olYellowFlagIcon Then
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #7  
Old May 5th 06, 03:59 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 6
Default VBA code to remove flag from all messages in Inbox

I made that change.....still not working. Is there something else I'm
missing?

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = obj
If Mail.FlagIcon = olYellowFlagIcon Then
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #8  
Old May 5th 06, 06:21 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default VBA code to remove flag from all messages in Inbox

Am 4 May 2006 18:59:57 -0700 schrieb :



No, you didn´t. See:

If TypeOf Item Is Outlook.MailItem Then



--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.vbOffice.net --


I made that change.....still not working. Is there something else I'm
missing?

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = obj
If Mail.FlagIcon = olYellowFlagIcon Then
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

  #9  
Old May 5th 06, 02:13 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 6
Default VBA code to remove flag from all messages in Inbox

I'm not understanding what you're saying I should change. I have a
line that states If TypeOf Item Is Outlook.MailItem Then. What part
do I need to fix? I don't have any skill with Outlook VBA, so I'm
basically looking to just copy and paste the code.

  #10  
Old May 5th 06, 03:25 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default VBA code to remove flag from all messages in Inbox

Reread Michael's earlier post, in which he said:

"Item" is not a declared variable. Replace it please by "obj".

You also need to remove the flag itself:

Mail.FlagStatus = olNoFlag

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

wrote in message ups.com...
I'm not understanding what you're saying I should change. I have a
line that states If TypeOf Item Is Outlook.MailItem Then. What part
do I need to fix? I don't have any skill with Outlook VBA, so I'm
basically looking to just copy and paste the code.

"Michael Bauer" wrote in message ...
Am 4 May 2006 18:59:57 -0700 schrieb :



No, you didn´t. See:

If TypeOf Item Is Outlook.MailItem Then



--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.vbOffice.net --


I made that change.....still not working. Is there something else I'm
missing?

Public Sub RemoveYellowFlagFromMessages()

Dim Items As Outlook.Items
Dim Mail As Outlook.MailItem
Dim obj As Object
Set Items = Application.Session.GetDefaultFolder(olFolderInbox ).Items
For Each obj In Items
If TypeOf Item Is Outlook.MailItem Then
Set Mail = obj
If Mail.FlagIcon = olYellowFlagIcon Then
Mail.FlagIcon = olNoFlagIcon
Mail.FlagRequest = vbNullString
Mail.Save
End If
End If
Next
End Sub

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using VBA code to automate a process [email protected] Outlook and VBA 7 April 21st 06 05:26 PM
Code to set an auto follow up flag A Don Outlook - Using Forms 1 April 21st 06 12:19 PM
Code to set Flag Status to complete on custom form ICT User Outlook - Using Forms 3 March 28th 06 12:59 AM
how to apply vba code to OL2003 forms ? TimR Outlook - Using Contacts 1 February 17th 06 05:41 PM
VBA Code to check Task Status [email protected] Outlook and VBA 2 February 3rd 06 07:16 PM


All times are GMT +1. The time now is 12:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.