Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Button to execute Add-in | Excel Discussion (Misc queries) | |||
concatenate and then execute? | Excel Worksheet Functions | |||
Could not execute | Excel Worksheet Functions | |||
VBA new function doesn't execute | Excel Programming | |||
tried to execute application from VBA | Excel Programming |