Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Looking for specific attachments in Outlook

Posted on 2006-11-03
9
Medium Priority
?
190 Views
Last Modified: 2010-04-08
In reference to this question ...

http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_22047080.html

Is it possible to make this go thru all the sub folders too?
0
Comment
Question by:kjanicke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17868653
Sure.  I'll make that change and get it posted as quick as I can (next 3-4 hours).
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 17869612
Try this, Karyl.  I recommend putting this in a module by itself.

'Change the file name and path as needed.
Const strFilename = "C:\eeTesting\Attachment Search Results.htm"
Dim objFSO As Object, _
    objFile As Object, _
    colExtensions As New Collection, _
    objIE As Object

Sub FindSpecificAttachmentType()
    Dim varExtensions As Variant, _
        arrExtensions As Variant, _
        varExtension As Variant
    varExtensions = InputBox("Enter one or more extensions to search for." & vbCrLf _
        & "Separate multiple extensions with spaces." & vbCrLf _
        & "Example: jpg tif tiff", "Attachment Type Search")
    arrExtensions = Split(varExtensions, " ")
    If IsArray(arrExtensions) Then
        For Each varExtension In arrExtensions
            colExtensions.Add LCase(varExtension), LCase(varExtension)
        Next
    Else
        colExtensions.Add LCase(varExtensions)
    End If
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile(strFilename)
    SearchFolder Application.ActiveExplorer.CurrentFolder
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing
    Set colExtensions = Nothing
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "file://" & strFilename
    Do While objIE.readyState <> 4
        DoEvents
    Loop
    objIE.Visible = True
    Set objIE = Nothing
End Sub

Sub SearchFolder(olkFolder As Outlook.MAPIFolder)
    Dim olkSubFolder As Outlook.MAPIFolder, _
        olkItem As Object, _
        olkAttachment As Outlook.Attachment
    For Each olkItem In olkFolder.Items
        If olkItem.Attachments.Count > 0 Then
            On Error Resume Next
            For Each olkAttachment In olkItem.Attachments
                varExtension = objFSO.GetExtensionName(LCase(olkAttachment.FileName))
                varItem = colExtensions.Item(varExtension)
                If Err.Number = 0 Then
                    strPath = olkItem.Parent.Path
                    objFile.WriteLine "<a href=""Outlook:" & olkItem.EntryID & """>" & olkItem.Subject & "</a><br>"
                    Exit For
                End If
            Next
            On Error GoTo 0
        End If
    Next
    For Each olkSubFolder In olkFolder.Folders
        SearchFolder olkSubFolder
    Next
    Set olkAttachment = Nothing
    Set olkItem = Nothing
    Set olkSubFolder = Nothing
End Sub
0
 
LVL 18

Author Comment

by:kjanicke
ID: 17869692
Have I told you before how much I love your code bits?

In the middle of a server crash so I'll have to try it later.

With my luck ... the next question i post will be "How do I recover testing all these code bits?"

THANKS!!!  You are awesome.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 76

Expert Comment

by:David Lee
ID: 17871208
You're far too kind, but thanks!  Hope the server crash doesn't turn ugly.
0
 
LVL 18

Author Comment

by:kjanicke
ID: 17872914
It works!!!  Thank you!!!

Of course the other sysadmin had to try it at the root level of the mailbox or on their PST's right away and it errored.

But if they want other functionaility ... well ... we both need to learn to code.

You are awesome.  Thanks.  
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17873341
Hmmm, it shouldn't matter what level it's started at or what folder it starts in.  I'll run some test and see what's going on.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17875192
Ok, I found a problem.  An error occurs when the code hits a Notes folder since notes don't support attachments.  I've adjusted the code to ignore everything but messages.  Replace the FindSpecificAttachmentType subroutine you have now with the one below.

Sub FindSpecificAttachmentType()
    Dim varExtensions As Variant, _
        arrExtensions As Variant, _
        varExtension As Variant
    varExtensions = InputBox("Enter one or more extensions to search for." & vbCrLf _
        & "Separate multiple extensions with spaces." & vbCrLf _
        & "Example: jpg tif tiff", "Attachment Type Search")
    arrExtensions = Split(varExtensions, " ")
    If IsArray(arrExtensions) Then
        For Each varExtension In arrExtensions
            colExtensions.Add LCase(varExtension), LCase(varExtension)
        Next
    Else
        colExtensions.Add LCase(varExtensions)
    End If
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile(strFilename)
    SearchFolder Application.ActiveExplorer.CurrentFolder
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing
    Set colExtensions = Nothing
    Set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 "file://" & strFilename
    Do While objIE.readyState <> 4
        DoEvents
    Loop
    objIE.Visible = True
    Set objIE = Nothing
End Sub
0
 
LVL 18

Author Comment

by:kjanicke
ID: 17880324
People usually get paid for this sort of thing.  Shouldn't you compile it into some sort of outlook add-on and post it for sale someplace?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 17886081
Yeah, I probably should.  I don't for a couple of reasons.  One of those is that I've found lots and lots of functional sample code on the internet.  Code that's helped me a lot.  I enjoy the challenge of solving problems, and this is my way of giving something back.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question