TheAntiGates
07-23-2007, 04:51 PM
My questions follow. I have barely any familiarity with OL objects but I'll try to fake my way through. I'm dangerous. :eek: Thanks for you true experts if you can offer guidance.
I essentially want to walk through all my mail messages, and depending on certain header traits, I'll [add code to] search the text and header, or just header. I'll try not to make too big a mess:Sub BrowseFolder()
Dim objTargetFolder As MAPIFolder, Item
If Application.ActiveExplorer.Selection.Count = 0 Then 'want to be able to go parent.parent
MsgBox "Select a(some) mail message(s) to use this.", vbInformation
Exit Sub
End If
Set Item = Application.ActiveExplorer.Selection.Item(1)
If Not GetFolder(olMailItem, objTargetFolder, Item) Then MsgBox "crap": Exit Sub
End Sub
Function GetFolder(pintFolderType, objFolder As MAPIFolder, oItem)
Dim objMyFolders As Outlook.Folders, objSession As Object, objMessage, Item, objSch As Search
Dim i As Integer, j As Integer
GetFolder = False
Set objMyFolders = oItem.Parent.Parent.Folders 'this gives 21 folders
Set objSession = CreateObject("MAPI.Session") ' Create MAPI session
objSession.Logon "", "", False, False, 0 ' Logon using an existing MAPI session
For i = 1 To objMyFolders.Count
If objMyFolders.Item(i).DefaultItemType = pintFolderType Then
Set objFolder=objMyFolders.Item(i) 'this is one "Deleted" (or something) msg
GetFolder = True
For j = 1 To objFolder.Items.Count
' Get the Outlook item with CDO
Set objMessage=objSession.GetMessage(objFolder.Items(j).EntryID,objFolder.Store ID)
Set objMessage = Nothing
Next j
'Set objSch = Application.AdvancedSearch(Scope:="Inbox", Filter:=strF, _
'SearchSubFolders:=True, Tag:="SubjectSearch")
'Use the AdvancedSearchComplete event to determine when a given search has completed.
End If
Next i
objSession.Logoff ' Close MAPI session
Set objSession = Nothing
If Not GetFolder Then
MsgBox "Problem getting folder", vbCritical, Application.Name
End If
End Function
It looks like (from shft-F9 or Watch window) objFolder.Items(j) has no properties and that you have to do a .GetMessage to do or know anything. Is that true, and if so, isn't that as bad as opening the message? I believe I'd prefer not opening it. *
Actually I'll be fine if I can just restrict to .unread=true, but I don't know how to get there. I guess I want to see the header without having to do .GetMessage.
FYI, I'm aiming for two things: to roll my own search macro since Outlook's supplied one is so sad; and to highlight and read any message header to see the true sender address 'ere opening a message. But right now all I've got is objMessage.Sender which - yep, I fear that it requires an opened message. :banghead:
GIA
* My understanding is that opening an OL email exposes any viruses/Trojans, and unless you have graphics shut off, pings that spammer to assuage him that I'm not only alive and well, but since I'm so doofus as to open spam, my address is 41,000 times more valuable on the open market. Woohoo! Be sure to send me a "Congratulations" popup! 14 times an hour, please!
I essentially want to walk through all my mail messages, and depending on certain header traits, I'll [add code to] search the text and header, or just header. I'll try not to make too big a mess:Sub BrowseFolder()
Dim objTargetFolder As MAPIFolder, Item
If Application.ActiveExplorer.Selection.Count = 0 Then 'want to be able to go parent.parent
MsgBox "Select a(some) mail message(s) to use this.", vbInformation
Exit Sub
End If
Set Item = Application.ActiveExplorer.Selection.Item(1)
If Not GetFolder(olMailItem, objTargetFolder, Item) Then MsgBox "crap": Exit Sub
End Sub
Function GetFolder(pintFolderType, objFolder As MAPIFolder, oItem)
Dim objMyFolders As Outlook.Folders, objSession As Object, objMessage, Item, objSch As Search
Dim i As Integer, j As Integer
GetFolder = False
Set objMyFolders = oItem.Parent.Parent.Folders 'this gives 21 folders
Set objSession = CreateObject("MAPI.Session") ' Create MAPI session
objSession.Logon "", "", False, False, 0 ' Logon using an existing MAPI session
For i = 1 To objMyFolders.Count
If objMyFolders.Item(i).DefaultItemType = pintFolderType Then
Set objFolder=objMyFolders.Item(i) 'this is one "Deleted" (or something) msg
GetFolder = True
For j = 1 To objFolder.Items.Count
' Get the Outlook item with CDO
Set objMessage=objSession.GetMessage(objFolder.Items(j).EntryID,objFolder.Store ID)
Set objMessage = Nothing
Next j
'Set objSch = Application.AdvancedSearch(Scope:="Inbox", Filter:=strF, _
'SearchSubFolders:=True, Tag:="SubjectSearch")
'Use the AdvancedSearchComplete event to determine when a given search has completed.
End If
Next i
objSession.Logoff ' Close MAPI session
Set objSession = Nothing
If Not GetFolder Then
MsgBox "Problem getting folder", vbCritical, Application.Name
End If
End Function
It looks like (from shft-F9 or Watch window) objFolder.Items(j) has no properties and that you have to do a .GetMessage to do or know anything. Is that true, and if so, isn't that as bad as opening the message? I believe I'd prefer not opening it. *
Actually I'll be fine if I can just restrict to .unread=true, but I don't know how to get there. I guess I want to see the header without having to do .GetMessage.
FYI, I'm aiming for two things: to roll my own search macro since Outlook's supplied one is so sad; and to highlight and read any message header to see the true sender address 'ere opening a message. But right now all I've got is objMessage.Sender which - yep, I fear that it requires an opened message. :banghead:
GIA
* My understanding is that opening an OL email exposes any viruses/Trojans, and unless you have graphics shut off, pings that spammer to assuage him that I'm not only alive and well, but since I'm so doofus as to open spam, my address is 41,000 times more valuable on the open market. Woohoo! Be sure to send me a "Congratulations" popup! 14 times an hour, please!