Hi. This is my first post here. please let me know if there is a more appropriate place to ask this:
I have the following VBA code (below) that works well for any mail in the "Inbox".
I execute it manually from the VBA ThisOutlookSession environment (Alt-F11)
But I also have lots of mail in folders from mapped PST files and what I want to do is make this code so that it works on whatever the "currently selected" folder is; even if it is a sub-folder in a PST file.
Is that possible?
Here is the code:
----------------Private Sub SetInitialProperties()
Dim ns As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim objUnknown As Object
Dim mail As Outlook.MailItem
Dim prop As Outlook.UserProperty
Set ns = Application.GetNamespace("MAPI")
Set fld = ns.GetDefaultFolder(olFolderInbox)
For Each objUnknown In fld.Items
If TypeOf objUnknown Is MailItem Then
... do stuff ...
End If
Next
Set objUnknown = Nothing
Set fld = Nothing
Set ns = Nothing
End Sub
--------------------Thanks!
-Rich
I have the following VBA code (below) that works well for any mail in the "Inbox".
I execute it manually from the VBA ThisOutlookSession environment (Alt-F11)
But I also have lots of mail in folders from mapped PST files and what I want to do is make this code so that it works on whatever the "currently selected" folder is; even if it is a sub-folder in a PST file.
Is that possible?
Here is the code:
----------------Private Sub SetInitialProperties()
Dim ns As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim objUnknown As Object
Dim mail As Outlook.MailItem
Dim prop As Outlook.UserProperty
Set ns = Application.GetNamespace("MAPI")
Set fld = ns.GetDefaultFolder(olFolderInbox)
For Each objUnknown In fld.Items
If TypeOf objUnknown Is MailItem Then
... do stuff ...
End If
Next
Set objUnknown = Nothing
Set fld = Nothing
Set ns = Nothing
End Sub
--------------------Thanks!
-Rich