Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button to execute Add-in Aerojade Excel Discussion (Misc queries) 3 October 3rd 08 09:46 PM
concatenate and then execute? miwarren Excel Worksheet Functions 6 October 17th 05 09:26 PM
Could not execute Gary Excel Worksheet Functions 1 December 20th 04 06:20 PM
VBA new function doesn't execute palasick[_3_] Excel Programming 0 October 1st 04 07:04 PM
tried to execute application from VBA Domagoj Vulin[_2_] Excel Programming 0 July 23rd 03 09:58 PM


All times are GMT +1. The time now is 09:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"