Results 1 to 4 of 4

Stop searching for file once a match is found.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-19-2010
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2003
    Posts
    107

    Question Stop searching for file once a match is found.

    I am currently running a macro that searches for a file with a rotating filename.

    The current code I am using works fine. However it returns and opens multiple files. I am using numerous search criteria as the file changes daily based on the time it was saved. I am trying to figure a way to stop the search once it finds a match and continue on with the rest of the macro.

    Dim FileDate As String
        FileDate = Application.InputBox("Please enter file date: (MM/DD/YYYY)")
    On Error Resume Next
        c00 = "\\wpccp001if\Apps\C3PO\PMG - Ben's\Network MPT Inclusion\ECMReports_Daily\"
        c01 = c00 & Format((FileDate), "yyyymmdd")
        Workbooks.Add c00 & Dir(c01 & " 220*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 215*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 214*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 213*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 210*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 205*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 204*campdata.csv")
        If Err.Number > 0 Then Workbooks.Add c00 & Dir(c01 & " 203*campdata.csv")
    Last edited by CJPHX; 05-21-2010 at 12:40 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1