PDA

View Full Version : Application.FileSearch replacement



legoatjames
11-11-2018, 07:37 AM
hello today i wrote my second function and im just learning vba so dont judge pls my code looks like that:


Public Sub OtworzKartke()
Dim Szukanie As FileSearch
Set Szukanie = Application.FileSearch




Szukanie.Filename = "Kartka tarminarza.xls"
Szukanie.LookIn = ThisWorkbook.Path


If Szukanie.Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then Workbooks.Open (ThisWorkbook.Path & "\Kartka terminarza.xls")


And as u can see i used Application.FileSearch which seems to dont work in excel 2016 and i was wondering how i can replace this to make my function work?

macropod
11-11-2018, 01:25 PM
Application.FileSearch was deprecated over a decade ago and has not been supported in Office since Office 2007 was released. For what you're trying to do, the Dir function should suffice.