Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New method for file search not working

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
Using previous advice, I have tried to create a new find file method to replace my old one that worked in excel 2003, with my current excel 2010. I am getting a compile error type mismatch which is highlighted in red. I was hoping someone could point out the error in my ways. Any help would be appreciated.

Code:
Sub Openallworkbooks()

Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim fs As Object

'
' Openallworkbooks Macro
' Macro recorded 3/30/2009
'
'Added 10/4/2011
[Red] Set fs = Application.FindFile [/Red]
With fs



'Set wbCodeBook = ThisWorkbook
'Commented out 10/4/2011

    'With Application.FileSearch
    'Commented out 10/4/2011
               
         'Change path to suit
        .LookIn = "C:\DailyC"
        .Filename = "ETF*.xls"
        
        '.FileType = msoFileTypeExcelWorkbooks
        'With Application.FileSearch
        'Commented out both lines 10/4/2011
                   

           ' If .Execute > 0 Then 'Workbooks in folder
            'Commented out line 10/4/2011
           If .Execute(SortBy:=msoSortByFileName, _
           SortOrder:=msoSortOrderAscending) > 0 Then
           
           
           
                For lCount = 1 To .FoundFiles.Count 'Loop through all.
                 'Open Workbook x and Set a Workbook variable to it
                 Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                 
                
                 Next lCount
            End If
    End With

    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True

'
End Sub
 
Hi,

Something I wrote in this thread might help you with your FileSearch problem...
Regards

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
To use FindFile correctly you want to assign the return value as a Boolean.

Looking a little more at your problem, I really don't think Application.FindFile will do what you think it will though.

Andy
---------------------------------
Zebracorn: 50% Zebra, 50% Unicorn = 100% Real.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top