Consulting

Results 1 to 3 of 3

Thread: HELP! application.filesearch wont work in excel 2010

  1. #1

    HELP! application.filesearch wont work in excel 2010

    Hi, could someone help me out with the code below. It worked in 2003 but not in 2010. I know nothing about VBA so I havent a hope in solving this on my own! The error is with application.filesearch. Hoping someone can work their magic and help get this working again. Thanks in advance.

        Dim blah As FileSearch
        Dim directory As String
        Dim i As Integer, iNewest As Integer
        Dim ws As Worksheet
        Set ws = ThisWorkbook.Worksheets("Risk")
        Dim LastMod As Object
       
        Sheets("VaR").Select
        MsgBox "Clearing Previous Portfolio Information"
      
         Sheets("VaR Works Export").Range("a4:h65536").ClearContents
         Sheets("VaR Works Export").Range("i5:w65536").ClearContents
        
        directory = "file://\\VarWorks"]\\VarWorks]"
        Set blah = Application.FileSearch
        With Application.FileSearch
            .NewSearch
            .Filename = "*VaR*"
            .LookIn = directory
            .LastModified = msoLastModifiedAnyTime
            .Execute msoSortByLastModified, msoSortOrderDescending
        End With
        If blah.FoundFiles.Count = 0 Then
        MsgBox "Has a VaR export report been generated?"
        Exit Sub
        Else
        End If
        
        
        ws.Range("b3").Value = blah.FoundFiles(1)
      
      ws.Range("b4").Value = FileDateTime(blah.FoundFiles(1))
    Workbooks.Open (blah.FoundFiles(1)), ReadOnly:=True
    MsgBox "Opening Last Modified File"
           
      Worksheets("VaR").Range(Cells(2, 1), Cells(Worksheets("VaR").Cells(Rows.Count, 1).End(xlUp).Row, 8)).Copy
        ThisWorkbook.Activate
        
         Sheets("Risk").Select
      MsgBox "Check DMD"
     Sheets("VaR").Select
    Cells(3, 1).Select
      
           Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
            xlNone, SkipBlanks:=False, Transpose:=False
                    Application.CutCopyMode = False
    Cells(3, 1).End(xlDown).Select
    lastrow = ActiveCell.Row
    Debug.Print lastrow
    If lastrow > 4 Then
    Workbooks("VaR Calculator.xls").Worksheets("VaR").Range("i4:w" & Trim(Str(lastrow))).FillDown
               MsgBox "Data Updated"
        
    End If
        Workbooks(Dir(blah.FoundFiles(1))).Close
     Name blah.FoundFiles(1) As "\\headfop006v\Archive\"]\\headfop006v\Archive" & Format(FileDateTime(blah.FoundFiles(1)), "YYYYMMDDHHMM") & "_VaR.xls"
     
    MsgBox "DMD Archived"
      
        
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Application.FileSearch was removed (no longer works) in 2007. I would suggest searching FSO remedies.

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    A few threads you might try are:
    http://www.vbaexpress.com/forum/showthread.php?49603
    http://www.vbaexpress.com/forum/showthread.php?49572
    http://www.vbaexpress.com/forum/showthread.php?45692
    http://answers.microsoft.com/en-us/o...5-0a83eb6bf984

    If you have a question about those, please post the thread number in a reply to this thread.

Tags for this Thread

Posting Permissions

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