ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Execute problems (https://www.excelbanter.com/excel-programming/325501-execute-problems.html)

Phil Floyd[_2_]

Execute problems
 
Below is a snippet of code I am using to import sheets into another
workbook. It works just fine on most computers, but on one when it gets to
the last line (I posted) it then goes to the End Sub. All of the computers
are running Excel 2002 or above. It doesn't seem to find any files in the
specified folder and there are several there. Can anyone shed some light?

Thanks,
Phil

With Application.FileSearch
.NewSearch
.LookIn = "C:\NCAA\Returned Brackets"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute() 0 Then



Dave Peterson[_5_]

Execute problems
 
Application.filesearch seems to be flakey.

Maybe you could use dir() to return all the files.

Kind of like:

Option Explicit
Sub ChangeOneCell_2A()

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim wkbk As Workbook

'change to point at the folder to check
myPath = "C:\NCAA\Returned Brackets"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myFiles) To UBound(myFiles)
Set wkbk = Workbooks.Open(myPath & myFiles(fCtr))
'do some neat stuff
wkbk.Close savechanges:=True 'False???
Next fCtr
End If

End Sub

Phil Floyd wrote:

Below is a snippet of code I am using to import sheets into another
workbook. It works just fine on most computers, but on one when it gets to
the last line (I posted) it then goes to the End Sub. All of the computers
are running Excel 2002 or above. It doesn't seem to find any files in the
specified folder and there are several there. Can anyone shed some light?

Thanks,
Phil

With Application.FileSearch
.NewSearch
.LookIn = "C:\NCAA\Returned Brackets"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute() 0 Then


--

Dave Peterson

Phil Floyd

Execute problems
 
Thanks Dave. I added the needed code to what you wrote and it works like a
charm.

Phil

"Dave Peterson" wrote in message
...
Application.filesearch seems to be flakey.

Maybe you could use dir() to return all the files.

Kind of like:

Option Explicit
Sub ChangeOneCell_2A()

Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim wkbk As Workbook

'change to point at the folder to check
myPath = "C:\NCAA\Returned Brackets"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myFiles) To UBound(myFiles)
Set wkbk = Workbooks.Open(myPath & myFiles(fCtr))
'do some neat stuff
wkbk.Close savechanges:=True 'False???
Next fCtr
End If

End Sub

Phil Floyd wrote:

Below is a snippet of code I am using to import sheets into another
workbook. It works just fine on most computers, but on one when it gets

to
the last line (I posted) it then goes to the End Sub. All of the

computers
are running Excel 2002 or above. It doesn't seem to find any files in

the
specified folder and there are several there. Can anyone shed some

light?

Thanks,
Phil

With Application.FileSearch
.NewSearch
.LookIn = "C:\NCAA\Returned Brackets"
.SearchSubFolders = False
.Filename = "*.xls"
If .Execute() 0 Then


--

Dave Peterson





All times are GMT +1. The time now is 03:12 AM.

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