Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application.FileSearch (2003)

    I have code that will zip cartain files in a directory. It looks like this. <pre> With Application.FileSearch
    .LookIn = "c:temp"
    .Filename = "*.xls"
    If .Execute(msoSortByLastModified, msoSortOrderAscending) > 0 Then
    TotFiles = .FoundFiles.Count
    End If
    End With

    For i = 1 To TotFiles
    Zip_Files (GetFilenameFromPath(Application.FileSearch.FoundF iles(i)))
    Pause 10
    Next i</pre>


    It almost always works fine. I have other code to attach the resulting .zip files to an e-mail. It looks like this:
    <pre> With Application.FileSearch
    .LookIn = "c:temp"
    .Filename = "*.zip"
    If .Execute(msoSortByLastModified, msoSortOrderAscending) > 0 Then
    TotFiles = .FoundFiles.Count
    End If
    End With
    For i = 1 To TotFiles
    oMailItem.Attachments.Add Application.FileSearch.FoundFiles(i)
    Next i</pre>


    More often than not, the second piece fails at this: <pre>If .Execute(msoSortByLastModified, msoSortOrderAscending) > 0 Then</pre>



    Am I missing something to make it work all the time? Is there a better way?
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Application.FileSearch (2003)

    I think FileSearch can't find .zip files because Windows XP sees them as (compressed) folders, not as files. You can replace the second part with
    <code>
    Dim strFile As String
    Dim strPath As String
    strPath = "C:Temp"
    strFile = Dir(strPath & "*.zip")
    Do While Not strFile = ""
    oMailItem.Attachments.Add strPath & strFile
    strFile = Dir
    Loop
    </code>
    The only difference is that the zip files will be sorted by name, ascending - you can't specifiy a different sort order using Dir.

  3. #3
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.FileSearch (2003)

    Worked perfectly, thank you!!
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

Posting Permissions

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