A Microsoft Office (Excel, Word) forum. OfficeFrustration

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 » OfficeFrustration forum » Microsoft Outlook » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Syntax to run a macro for several folders



 
 
Thread Tools Display Modes
  #1  
Old April 30th, 2010, 04:44 PM posted to microsoft.public.outlook.general
dhstein
external usenet poster
 
Posts: 665
Default Syntax to run a macro for several folders

I have the following macro to mark all messages as read. I want to call it
with a list so that it will run for several folders. What syntax would I
use? Thanks.

Sub ChangeToRead()

Dim objInbox As Outlook.MAPIFolder
Dim objOutlook As Object, objnSpace As Object, objMessage As Object
Dim objSubfolder As Outlook.MAPIFolder

Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objInbox = objnSpace.GetDefaultFolder(olFolderInbox)
'Set objSubfolder = objInbox.Folders.Item("Test")
Set objSubfolder = Application.ActiveExplorer.CurrentFolder

For Each objMessage In objSubfolder.Items
objMessage.UnRead = False
Next

Set objOutlook = Nothing
Set objnSpace = Nothing
Set objInbox = Nothing
Set objSubfolder = Nothing


End Sub

  #2  
Old May 3rd, 2010, 08:21 AM posted to microsoft.public.outlook.general
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,346
Default Syntax to run a macro for several folders



See you own code, it demonstrates how to call a subfolder of the inbox, for
instance.

--
Best regards
Michael Bauer - MVP Outlook
Category Manager - Manage and share your categories:
SAM - The Sending Account Manager:
http://www.vboffice.net/product.html?lang=en


Am Fri, 30 Apr 2010 08:44:02 -0700 schrieb dhstein:

I have the following macro to mark all messages as read. I want to call

it
with a list so that it will run for several folders. What syntax would I
use? Thanks.

Sub ChangeToRead()

Dim objInbox As Outlook.MAPIFolder
Dim objOutlook As Object, objnSpace As Object, objMessage As Object
Dim objSubfolder As Outlook.MAPIFolder

Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objInbox = objnSpace.GetDefaultFolder(olFolderInbox)
'Set objSubfolder = objInbox.Folders.Item("Test")
Set objSubfolder = Application.ActiveExplorer.CurrentFolder

For Each objMessage In objSubfolder.Items
objMessage.UnRead = False
Next

Set objOutlook = Nothing
Set objnSpace = Nothing
Set objInbox = Nothing
Set objSubfolder = Nothing


End Sub

 




Thread Tools
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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.