View Single Post
  #25   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Code looping through files

In a different branch of this thread,

It's a long thread and I jumped in the middle of it without reading
everything.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Dave Peterson" wrote in message
...
In a different branch of this thread, Bob wrote that he saw this in the
msgbox
for the full name:

C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls

It doesn't look like it's a MAC (from a non-MAC user).

Otto Moehrbach wrote:

Chip
I will check with him this morning and let you know. It never
occurred
to me that he might have a Mac. Otto
"Chip Pearson" wrote in message
...
Otto,

This is out of the blue, but perhaps the user having the problem is
using
a Macintosh? If this proves to be the case, the code will fail on the
line
indicated because Macs don't use the '\' character as a path separator.
Instead, they use, I think, a ':' character. Instead of hard coding the
'\', use Application.PathSeparator. E.g.,

Set wb = Workbooks.Open(MyPath & Application.PathSeparator & TheFile)

The code you posted works fine for me in Excel 2007 for Windows.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Otto Moehrbach" wrote in message
...
Tom
Thanks for your help as well as Dave and Chip. Here's what the OP
and
I just did to establish a hard starting point. He set all the code I
had
written for him aside. Instead, he used the macro from:
http://www.contextures.com/xlfaqMac.html#LoopBooks

with NO CHANGES of any kind. No other macro or macro call was used.

He established a path in his computer to match that used in the macro
and
placed his test files in that folder.

He ran the macro.

The error message is:

Run-time error '1004'

Method 'Open' of object 'Workbook' failed.

The highlighted code line is the "Set wb = ............"

The full macro is:

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End SubWe will try any suggestion you and the others can come up with.
Thanks for your time. Otto"Tom Ogilvy" wrote in
message ...
Since you don't show the code, have him send you the file that fails
to
open and test the code with that file. Perhaps the file is damaged
or
not a file Excel will open.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel XP & Win XP
I'm helping an OP with a project. The code loops through all the
files
in a folder, opens each, does things, closes the file and opens the
next file, etc.
The code is placed in the Personal.xls file. It works fine for me.
It
fails on opening the first file for him (will not open the file).
An
error is produced saying that opening the file failed. He has Excel
2003.
He sent me his Personal.xls file. I changed the name and put it in
my
XLSTART folder. It works fine with my path. I created his path on
my
computer and that works fine too.
I checked the VBE - Tools - References. The only thing I have
checked
that he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't
have anything like that to check.
Does anyone have any ideas of what I could do? Thanks for your
time.
Otto









--

Dave Peterson