ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   FileSearch Object - Cannot assign to variable (https://www.excelbanter.com/excel-programming/321452-filesearch-object-cannot-assign-variable.html)

Alan

FileSearch Object - Cannot assign to variable
 

Hi All,

Can anyone help me understand why the following code does not work:

It bombs on the penultimate line (myFiles = ...)

I was hoping to use myFiles to recursively open each file in that
collection, and then copy / paste to a master file (new worksheet for
each file) to get each separate xls file into a single workbook.

BTW, for the avoidance of doubt, every file in the C:\Temp folder *is*
an excel file.

Thanks,

Alan.


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub GetFiles()

With Application.FileSearch

.LookIn = "C:\Temp"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.Execute

End With

myFiles = Application.FileSearch.FoundFiles

End Sub

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+





Tom Ogilvy

FileSearch Object - Cannot assign to variable
 
Sub GetFiles()
set fs = application.FileSearch
with fs
.NewSearch
.LookIn = "C:\Temp"
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
if .Execute 0 then
for i = 1 to .foundfiles.count
set wkbk = worbooks.open .foundfiles(i)
'
wkbk.close Savechanges:=False
next
End if
End With

--
Regards,
Tom Ogilvy


"Alan" wrote in message
...

Hi All,

Can anyone help me understand why the following code does not work:

It bombs on the penultimate line (myFiles = ...)

I was hoping to use myFiles to recursively open each file in that
collection, and then copy / paste to a master file (new worksheet for
each file) to get each separate xls file into a single workbook.

BTW, for the avoidance of doubt, every file in the C:\Temp folder *is*
an excel file.

Thanks,

Alan.


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub GetFiles()

With Application.FileSearch

.LookIn = "C:\Temp"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.Execute

End With

myFiles = Application.FileSearch.FoundFiles

End Sub

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+








All times are GMT +1. The time now is 06:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com