Results 1 to 2 of 2

Thread: Search in Outlook for an attachment?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878

    Search in Outlook for an attachment?

    Anyone have any ideas on how to search in Outlook for something? Initiated from VBScript (ideally) or standard VB.

    First pass - Search for a subject with "XXX" in it.
    Second pass - Search for a message with "XXX" in the body of the message somewhere.
    Third pass (and the one I actually want!) - Search for a message with an attachment called "XXX.DOC".

    The output can be a simple MsgBox with the subject of the mail message.

    Thanks, Chris

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    It needs changing in order to handle recursion (folders within folders) better. It needs changing to display what its found in a file, rather than in a msg box. However, this .VBS script does look for all attachments of the form 15*.* and 16*.* within the first 3 levels of folders.

    If you want to test it, their is a MSGBOX near the beginning thats worth un-commenting.

    VB Code:
    1. msgbox "Searching Outlook for certain attachments . . ."
    2.  
    3. '
    4. ' First the sub-routine that looks through a specified folder looking for mail
    5. '  items and attachments
    6. '
    7. sub LookThroughFolder (thisFolder)
    8.     if thisFolder.Count > 0 then
    9.     set myItem = thisFolder.GetFirst
    10. ' msgbox "IN FOLDER: " & myItem.parent & " ARE " & thisFolder.count & " ITEMS. FIRST ONE IS: " & myItem
    11. '
    12. ' Step through all items in that Folder
    13. '
    14.     for k = 1 to thisFolder.count
    15.     if myItem.class = "43" then
    16.         if myItem.attachments.count > 0 then
    17. '
    18. ' For any mail item (class 43) with an attachment, check its name
    19. '
    20.             if myItem.Attachments(1) > "15" and myItem.Attachments(1) < "17" then
    21.                 msgbox "FOUND IN = " & myItem.Parent & "(IN: " & myitem.parent.parent & ")" & ". SUBJECT = " & myItem & ". ATTACHMENT = " & myItem.Attachments(1)
    22.             end if
    23.         end if
    24.     end if
    25. '
    26. ' Now look at the next item in the folder
    27. '
    28.     set MyItem = thisfolder.GetNext
    29.     next
    30.     end if
    31. end sub
    32.  
    33. '
    34. ' Now for the actual code, that steps through your mailbox and .PSTs...
    35. '
    36. set ol = getobject(,"outlook.application")
    37. set mapi=ol.getnamespace("MAPI")
    38. '
    39. ' Step through all folders in your profile
    40. '
    41. for i = 1 to mapi.folders.count
    42. '
    43. ' Ignore the Public Folders
    44. '
    45.     if mapi.folders(i) <> "Public Folders" then
    46.         set myStore = mapi.folders(i)
    47.         rtn = msgbox ("Store = " & myStore, 1)
    48.         if rtn <> 2 then
    49.             set myFolders = myStore.folders
    50. '
    51. ' Step through all folders in that Store
    52. '
    53.             for j = 1 to myFolders.Count
    54.                 LookThroughFolder (myFolders(j).Items)
    55.                 set mySubFolders = myFolders(j).folders
    56.                 for m = 1 to mySubFolders.count
    57. '
    58. ' If we have any sub-folders, look through those.
    59. '
    60.                     LookThroughFolder (mySubFolders(m).items)
    61.                     set mySubSubFolders = mySubFolders(m).folders
    62.                     for n = 1 to mySubSubFolders.count
    63. '
    64. ' If we have any sub-folders of those sub-folders, look through those.
    65. '
    66.                         LookThroughFolder (mySubSubFolders(n).items)
    67.                     next
    68.                 next
    69.             next
    70.         end if
    71.     end if
    72. next
    73.  
    74. Msgbox "Ending the search . . ."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width