Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
loop does not work correctly
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Dave Peterson, post: 9037169"] There have be a lot of posts describing the troubles with .filesearch--trouble arise with some versions of excel/windows. If you're positive that there are 4 excel files in that folder, maybe using the old Dir() to retrieve the filenames would be better. Option Explicit Sub testme01() Dim myNames() 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:\Tranportation" If Right(myPath, 1) <> "\" Then myPath = myPath & "\" End If myFile = "" On Error Resume Next myFile = Dir(myPath & "*.xls") On Error GoTo 0 If myFile = "" Then MsgBox "no files found" Exit Sub End If Application.ScreenUpdating = False 'get the list of files fCtr = 0 Do While myFile <> "" fCtr = fCtr + 1 ReDim Preserve myNames(1 To fCtr) myNames(fCtr) = myFile myFile = Dir() Loop If fCtr > 0 Then For fCtr = LBound(myNames) To UBound(myNames) Application.StatusBar _ = "Processing: " & myNames(fCtr) & " at: " & Now Set wkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr)) 'your code to do all the work here wkbk.Close savechanges:=False Next fCtr End If With Application .ScreenUpdating = True .StatusBar = False End With End Sub [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft Excel
Microsoft Excel Programming
loop does not work correctly
Top