Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Code looping through files

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Code looping through files

It is suspicious that opening is the problem.

Make sure that the Security settings for Excel are the same on both machines.
--
Gary's Student


"Otto Moehrbach" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Code looping through files

Do you know the exact wording of the error message? Is it coming from Excel
or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.


That's a big clue. Does he really not have the Forms library listed in the
References list box? Even if it not checked, it should be present in the
list. MSFORMS is part of the basic Excel installation, not optional in any
way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all in the
References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and re-register
Excel. Close Excel (and all other Office programs), go to the Windows Start
menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just "Excel.exe".
In the Immediate window of VBA, enter the following and press Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a UserForm to
the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error message
when trying to add a UserForm, try to add the reference to MSFORMS manually.
In the References dialog, click "Browse" and navigate to the file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file, then
you'll probably want to run "Detect And Repair" from the Help menu. If this
doesn't fix the problem, you'll likely need to uninstall and reinstall
Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file indicates
that something serious has gone on.


--
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
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

You might ask if the OP is able to use controls from the control toolbox
toolbar in Excel.

If he can, then he might not be giving you correct information on the
Microsoft Forms 2.0 Object library being available to select.

--
Regards,
Tom Ogilvy


"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.


That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present in
the list. MSFORMS is part of the basic Excel installation, not optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file, then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file indicates
that something serious has gone on.


--
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
...
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








  #6   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Hi, I've got the problem that Otto is helping me with. I've done a complete
detect and repair and as Chip has suggested I've looked in the References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also attempted to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.


That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present in
the list. MSFORMS is part of the basic Excel installation, not optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file, then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file indicates
that something serious has gone on.


--
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
...
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






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a complete
detect and repair and as Chip has suggested I've looked in the References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also attempted to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.


That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present in
the list. MSFORMS is part of the basic Excel installation, not optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file, then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file indicates
that something serious has gone on.


--
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
...
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
  #8   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Run Time Error 1004 Method OPEN of object.workbooks failed. This is in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error

line.

I've sent Otto the files while he was working on the code. The code works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also attempted
to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not optional
in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all
in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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



  #9   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

As another note, I removed all macro securtiy and still the problem is
there..

"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also attempted
to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not optional
in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all
in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

What do you see in the msgbox right before it fails?

Do you see "daily error report master.xls"?

If you do, then I'm guessing that the code that you're running is in a file with
that name.

Maybe this would help:

If lcase(TheFile) < lcase("Daily Error report MASTER.xls") Then

(or maybe not!)


rjr wrote:

Run Time Error 1004 Method OPEN of object.workbooks failed. This is in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error

line.

I've sent Otto the files while he was working on the code. The code works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.

"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also attempted
to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not optional
in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all
in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms 2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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


--

Dave Peterson


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually have a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This is in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error

line.

I've sent Otto the files while he was working on the code. The code works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the
error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed
in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at all
in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms
2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu. If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





  #12   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

I put Tom's in and the msgbox returned the complete directory that we're
using as the directory and the proper file name. It still errored out on the
Set wb line...
I'm thinking that it has to do with some setting I've got on my computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually have a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This is in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error

line.

I've sent Otto the files while he was working on the code. The code works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the
error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed
in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms
2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu.
If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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







  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that we're
using as the directory and the proper file name. It still errored out on the
Set wb line...
I'm thinking that it has to do with some setting I've got on my computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually have a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This is in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error
line.

I've sent Otto the files while he was working on the code. The code works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library installed and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch, absolutely no
problem.

I did send the file to Otto and he can't recreate the problem. The code
performs as it should on his machine and completes. I still get the
error
and the code stops, as Otto has said. Is there anything that anyone can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't have
anything like that to check.

That's a big clue. Does he really not have the Forms library listed
in
the References list box? Even if it not checked, it should be present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft Forms
2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the file,
then
you'll probably want to run "Detect And Repair" from the Help menu.
If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson
  #14   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

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

This is the location of where the file is and the asf.xls is the file that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob


"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that we're
using as the directory and the proper file name. It still errored out on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error
line.

I've sent Otto the files while he was working on the code. The code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library installed
and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch, absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem. The
code
performs as it should on his machine and completes. I still get the
error
and the code stops, as Otto has said. Is there anything that anyone
can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms library
listed
in
the References list box? Even if it not checked, it should be
present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft
Forms
2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the
file,
then
you'll probably want to run "Detect And Repair" from the Help
menu.
If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson



  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file.

If you create a separate procedure in a test module:

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the original
procedure work ok?

I can't imagine what can be happening where you can open this file manually, but
have problems when you open it via code.

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that we're
using as the directory and the proper file name. It still errored out on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) << error
line.

I've sent Otto the files while he was working on the code. The code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library installed
and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch, absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem. The
code
performs as it should on his machine and completes. I still get the
error
and the code stops, as Otto has said. Is there anything that anyone
can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms library
listed
in
the References list box? Even if it not checked, it should be
present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft
Forms
2.0
Object Library" appears in the list of references. Try adding a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an error
message
when trying to add a UserForm, try to add the reference to MSFORMS
manually. In the References dialog, click "Browse" and navigate to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the
file,
then
you'll probably want to run "Detect And Repair" from the Help
menu.
If
this doesn't fix the problem, you'll likely need to uninstall and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson


--

Dave Peterson


  #16   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files


"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file. ***
none of the files are locked or protected.

If you create a separate procedure in a test module:


*****No because what we're trying to do is go down the directory of .xls
files and open, do the procedure and then close -- move to next one and redo
the procedure until all files (approx 22) have had the code run on them and
it's completed.

I will add that if I take this portion (where the error occurs) of the code
out of it, the code runs perfectly on each file operated independently but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.


It will open by single code, like I said, but once we try it through the
loop he hangs up right there. Otto has it working fine (With the same files)
on his computer and I even transferred all my miles and code to another
laptop I have running windows xp pro and office 2003 with the same exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to isolate
mine as the cause. Is there any reasons that you can think of..... Lastly
do you think removing and reinstalling office would help. I can't see where
it would since all features are installed, but I don't know enough to make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that
we're
using as the directory and the proper file name. It still errored out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This
is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) <<
error
line.

I've sent Otto the files while he was working on the code. The code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done
a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem.
The
code
performs as it should on his machine and completes. I still get
the
error
and the code stops, as Otto has said. Is there anything that
anyone
can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms library
listed
in
the References list box? Even if it not checked, it should be
present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear
at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft
Forms
2.0
Object Library" appears in the list of references. Try adding
a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an
error
message
when trying to add a UserForm, try to add the reference to
MSFORMS
manually. In the References dialog, click "Browse" and navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the
file,
then
you'll probably want to run "Detect And Repair" from the Help
menu.
If
this doesn't fix the problem, you'll likely need to uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson


--

Dave Peterson



  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Code looping through files

Thanks Tom. He did send me the group of files that he is using, so we both
have the same identical files on both our computers. 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






  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Code looping through files

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






  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Code looping through files

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








  #20   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition with
all current updates and a valid updated Office Professional product.
As a side note I've also placed it on my Dell D520 laptop with Windoes XP
Professional and Office 2003 with the exact same results. Since it works for
everyone else it obviously has to be something with my computers, but WHAT?
My dell laptop is relatively clean without a lot of additional programs and
the results are the same. That's why I think the problem lies with my
machine's setup...

Bob R

"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












  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Code looping through files

this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition with all
current updates and a valid updated Office Professional product.
As a side note I've also placed it on my Dell D520 laptop with Windoes XP
Professional and Office 2003 with the exact same results. Since it works for
everyone else it obviously has to be something with my computers, but WHAT? My
dell laptop is relatively clean without a lot of additional programs and the
results are the same. That's why I think the problem lies with my machine's
setup...

Bob R

"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












  #22   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Code looping through files

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










  #23   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

I wanted you to try the separate procedure as a test--not a replacement for the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file. ***
none of the files are locked or protected.

If you create a separate procedure in a test module:


*****No because what we're trying to do is go down the directory of .xls
files and open, do the procedure and then close -- move to next one and redo
the procedure until all files (approx 22) have had the code run on them and
it's completed.

I will add that if I take this portion (where the error occurs) of the code
out of it, the code runs perfectly on each file operated independently but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.


It will open by single code, like I said, but once we try it through the
loop he hangs up right there. Otto has it working fine (With the same files)
on his computer and I even transferred all my miles and code to another
laptop I have running windows xp pro and office 2003 with the same exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to isolate
mine as the cause. Is there any reasons that you can think of..... Lastly
do you think removing and reinstalling office would help. I can't see where
it would since all features are installed, but I don't know enough to make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that
we're
using as the directory and the proper file name. It still errored out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This
is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) <<
error
line.

I've sent Otto the files while he was working on the code. The code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done
a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem.
The
code
performs as it should on his machine and completes. I still get
the
error
and the code stops, as Otto has said. Is there anything that
anyone
can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms library
listed
in
the References list box? Even if it not checked, it should be
present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear
at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft
Forms
2.0
Object Library" appears in the list of references. Try adding
a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an
error
message
when trying to add a UserForm, try to add the reference to
MSFORMS
manually. In the References dialog, click "Browse" and navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the
file,
then
you'll probably want to run "Detect And Repair" from the Help
menu.
If
this doesn't fix the problem, you'll likely need to uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #24   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

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
  #25   Report Post  
Posted to microsoft.public.excel.programming
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





  #26   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

I had to go back to make sure that my memory wasn't playing tricks on me after I
read your post.



Chip Pearson wrote:

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


--

Dave Peterson
  #27   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Code looping through files

Dave
Bob replied in this thread that it was not a MAC. Otto
"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



  #28   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

I suffer the same problem as Chip <vbg.

Otto Moehrbach wrote:

Dave
Bob replied in this thread that it was not a MAC. Otto
"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


--

Dave Peterson
  #29   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP Media
Edition 2005. I can't get it to work on my computer at all, so I thought I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop. She is
running Windows XP Home and Office 2000 Professional and consequently Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible or
is there an issue with 2003 that needs to be turned on to make them work.?
I really need to make this work on an Excel 2003 program so I'm kinda back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file. ***
none of the files are locked or protected.

If you create a separate procedure in a test module:


*****No because what we're trying to do is go down the directory of .xls
files and open, do the procedure and then close -- move to next one and
redo
the procedure until all files (approx 22) have had the code run on them
and
it's completed.

I will add that if I take this portion (where the error occurs) of the
code
out of it, the code runs perfectly on each file operated independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.


It will open by single code, like I said, but once we try it through the
loop he hangs up right there. Otto has it working fine (With the same
files)
on his computer and I even transferred all my miles and code to another
laptop I have running windows xp pro and office 2003 with the same exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't see
where
it would since all features are installed, but I don't know enough to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that
we're
using as the directory and the proper file name. It still errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed.
This
is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) <<
error
line.

I've sent Otto the files while he was working on the code. The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the
file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've
done
a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem.
The
code
performs as it should on his machine and completes. I still
get
the
error
and the code stops, as Otto has said. Is there anything that
anyone
can
think of that I can do that he and I haven't. If uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it should
be
present
in
the list. MSFORMS is part of the basic Excel installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't
appear
at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get an
error
message
when trying to add a UserForm, try to add the reference to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find
the
file,
then
you'll probably want to run "Detect And Repair" from the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson


--

Dave Peterson



  #30   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Code looping through files

the code i posted worked in xl2003

--


Gary


"rjr" wrote in message
. ..
Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP Media
Edition 2005. I can't get it to work on my computer at all, so I thought I'd
try my laptop which is new and has Excel 2003 Professional, along with Windows
XP Professional also. Then I decided to try my wife's laptop. She is running
Windows XP Home and Office 2000 Professional and consequently Excel 2000
Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it would
do and did on his computer.
Now my question is does anyone know of a reason this should be possible or is
there an issue with 2003 that needs to be turned on to make them work.?
I really need to make this work on an Excel 2003 program so I'm kinda back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file. ***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of .xls
files and open, do the procedure and then close -- move to next one and redo
the procedure until all files (approx 22) have had the code run on them and
it's completed.

I will add that if I take this portion (where the error occurs) of the code
out of it, the code runs perfectly on each file operated independently but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through the
loop he hangs up right there. Otto has it working fine (With the same files)
on his computer and I even transferred all my miles and code to another
laptop I have running windows xp pro and office 2003 with the same exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to isolate
mine as the cause. Is there any reasons that you can think of..... Lastly
do you think removing and reinstalling office would help. I can't see where
it would since all features are installed, but I don't know enough to make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that
we're
using as the directory and the proper file name. It still errored out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed. This
is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) <<
error
line.

I've sent Otto the files while he was working on the code. The code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've done
a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem.
The
code
performs as it should on his machine and completes. I still get
the
error
and the code stops, as Otto has said. Is there anything that
anyone
can
think of that I can do that he and I haven't. If uninstalling and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms library
listed
in
the References list box? Even if it not checked, it should be
present
in
the list. MSFORMS is part of the basic Excel installation, not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't appear
at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that "Microsoft
Forms
2.0
Object Library" appears in the list of references. Try adding
a
UserForm
to the project. Doing so will automatically add a reference to
MSFORMS.

If this fails, and you (by which I mean your user) get an
error
message
when trying to add a UserForm, try to add the reference to
MSFORMS
manually. In the References dialog, click "Browse" and navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find the
file,
then
you'll probably want to run "Detect And Repair" from the Help
menu.
If
this doesn't fix the problem, you'll likely need to uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson


--

Dave Peterson







  #31   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Code looping through files

First, did you try that little subroutine?

Otto posted this code as the basis for the code you're using.

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 Sub

This could cause trouble if the logged drive isn't the C: drive. (Changing the
folder won't change the drive.)

Does adding another line help?

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
ChDrive myPath '<--- Added
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub

rjr wrote:

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP Media
Edition 2005. I can't get it to work on my computer at all, so I thought I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop. She is
running Windows XP Home and Office 2000 Professional and consequently Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible or
is there an issue with 2003 that needs to be turned on to make them work.?
I really need to make this work on an Excel 2003 program so I'm kinda back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file. ***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of .xls
files and open, do the procedure and then close -- move to next one and
redo
the procedure until all files (approx 22) have had the code run on them
and
it's completed.

I will add that if I take this portion (where the error occurs) of the
code
out of it, the code runs perfectly on each file operated independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through the
loop he hangs up right there. Otto has it working fine (With the same
files)
on his computer and I even transferred all my miles and code to another
laptop I have running windows xp pro and office 2003 with the same exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't see
where
it would since all features are installed, but I don't know enough to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory that
we're
using as the directory and the proper file name. It still errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work, but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed.
This
is
in
the Microsoft vb alert window. the Error place in the code is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile) <<
error
line.

I've sent Otto the files while he was working on the code. The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the
file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've
done
a
complete
detect and repair and as Chip has suggested I've looked in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the problem.
The
code
performs as it should on his machine and completes. I still
get
the
error
and the code stops, as Otto has said. Is there anything that
anyone
can
think of that I can do that he and I haven't. If uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it should
be
present
in
the list. MSFORMS is part of the basic Excel installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't
appear
at
all in
the References list, the basic installation of Excel is bad.

The first thing I'd advise to your user is to unregister and
re-register
Excel. Close Excel (and all other Office programs), go to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get an
error
message
when trying to add a UserForm, try to add the reference to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't find
the
file,
then
you'll probably want to run "Detect And Repair" from the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #32   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

Certainly a reasonable suggestion, but more consistent with a file not found
type error.

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
First, did you try that little subroutine?

Otto posted this code as the basis for the code you're using.

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 Sub

This could cause trouble if the logged drive isn't the C: drive.
(Changing the
folder won't change the drive.)

Does adding another line help?

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
ChDrive myPath '<--- Added
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub

rjr wrote:

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP Media
Edition 2005. I can't get it to work on my computer at all, so I thought
I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop. She
is
running Windows XP Home and Office 2000 Professional and consequently
Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible
or
is there an issue with 2003 that needs to be turned on to make them
work.?
I really need to make this work on an Excel 2003 program so I'm kinda
back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially
on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement
for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file.
***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of
.xls
files and open, do the procedure and then close -- move to next one
and
redo
the procedure until all files (approx 22) have had the code run on
them
and
it's completed.

I will add that if I take this portion (where the error occurs) of the
code
out of it, the code runs perfectly on each file operated independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through
the
loop he hangs up right there. Otto has it working fine (With the same
files)
on his computer and I even transferred all my miles and code to
another
laptop I have running windows xp pro and office 2003 with the same
exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't see
where
it would since all features are installed, but I don't know enough to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the
file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox
showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory
that
we're
using as the directory and the proper file name. It still
errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't
actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work,
but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed.
This
is
in
the Microsoft vb alert window. the Error place in the code is
at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)
<<
error
line.

I've sent Otto the files while he was working on the code.
The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the
file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you
don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've
done
a
complete
detect and repair and as Chip has suggested I've looked in
the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the
problem.
The
code
performs as it should on his machine and completes. I still
get
the
error
and the code stops, as Otto has said. Is there anything
that
anyone
can
think of that I can do that he and I haven't. If
uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it
should
be
present
in
the list. MSFORMS is part of the basic Excel
installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't
appear
at
all in
the References list, the basic installation of Excel is
bad.

The first thing I'd advise to your user is to unregister
and
re-register
Excel. Close Excel (and all other Office programs), go to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead
of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use
that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a
reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get
an
error
message
when trying to add a UserForm, try to add the reference
to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't
find
the
file,
then
you'll probably want to run "Detect And Repair" from the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing
FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson



  #33   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Gary my apologies, I used your code as a standalone and the first loop
worked fine and opened the first file, but when it did the loop errored out
as did Otto's, on the second round. This is the same thing that happened
with Otto's code and does it consistentantly with my desktop and my laptop.

I'm sorry for not getting back with you on this. Can you think of a reason
your 2003 would work and mine wouldn't?
Bob Reynolds


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition with
all current updates and a valid updated Office Professional product.
As a side note I've also placed it on my Dell D520 laptop with Windoes XP
Professional and Office 2003 with the exact same results. Since it works
for everyone else it obviously has to be something with my computers, but
WHAT? My dell laptop is relatively clean without a lot of additional
programs and the results are the same. That's why I think the problem
lies with my machine's setup...

Bob R

"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














  #34   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy



"rjr" wrote in message
.. .
Gary my apologies, I used your code as a standalone and the first loop
worked fine and opened the first file, but when it did the loop errored
out as did Otto's, on the second round. This is the same thing that
happened with Otto's code and does it consistentantly with my desktop and
my laptop.

I'm sorry for not getting back with you on this. Can you think of a reason
your 2003 would work and mine wouldn't?
Bob Reynolds


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition
with all current updates and a valid updated Office Professional
product.
As a side note I've also placed it on my Dell D520 laptop with Windoes
XP Professional and Office 2003 with the exact same results. Since it
works for everyone else it obviously has to be something with my
computers, but WHAT? My dell laptop is relatively clean without a lot of
additional programs and the results are the same. That's why I think the
problem lies with my machine's setup...

Bob R

"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
















  #35   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Dave, my apologies for not getting back sooner, kinda forgot where I'm at .

Yes I tried the subroutine you provided
Option Explicit
Sub Testme01()
Dim myName As String
Dim wb As Workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

Set wb = Workbooks.Open(myName)
End Sub

and it worked fine. I changed the my name to c:\temp which is where we we're
now working out of. It seems the problem occurs when the code loops and it
won't open the second file as it did the first. I am able to open all the
files in that folder individually, but not through the code. I also tried
Gary's little routine that worked on 2003 and it stopped at the same
location as Otto's code did.
Is that a setting that might be creating problems for me inside of 2003?

Thanks again
Bob Reynolds
"Dave Peterson" wrote in message
...
First, did you try that little subroutine?

Otto posted this code as the basis for the code you're using.

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 Sub

This could cause trouble if the logged drive isn't the C: drive.
(Changing the
folder won't change the drive.)

Does adding another line help?

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
ChDrive myPath '<--- Added
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub

rjr wrote:

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP Media
Edition 2005. I can't get it to work on my computer at all, so I thought
I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop. She
is
running Windows XP Home and Office 2000 Professional and consequently
Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible
or
is there an issue with 2003 that needs to be turned on to make them
work.?
I really need to make this work on an Excel 2003 program so I'm kinda
back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially
on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement
for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file.
***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of
.xls
files and open, do the procedure and then close -- move to next one
and
redo
the procedure until all files (approx 22) have had the code run on
them
and
it's completed.

I will add that if I take this portion (where the error occurs) of the
code
out of it, the code runs perfectly on each file operated independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through
the
loop he hangs up right there. Otto has it working fine (With the same
files)
on his computer and I even transferred all my miles and code to
another
laptop I have running windows xp pro and office 2003 with the same
exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't see
where
it would since all features are installed, but I don't know enough to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the
file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox
showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory
that
we're
using as the directory and the proper file name. It still
errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't
actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work,
but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed.
This
is
in
the Microsoft vb alert window. the Error place in the code is
at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)
<<
error
line.

I've sent Otto the files while he was working on the code.
The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on the
file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you
don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with. I've
done
a
complete
detect and repair and as Chip has suggested I've looked in
the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the
problem.
The
code
performs as it should on his machine and completes. I still
get
the
error
and the code stops, as Otto has said. Is there anything
that
anyone
can
think of that I can do that he and I haven't. If
uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it
should
be
present
in
the list. MSFORMS is part of the basic Excel
installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't
appear
at
all in
the References list, the basic installation of Excel is
bad.

The first thing I'd advise to your user is to unregister
and
re-register
Excel. Close Excel (and all other Office programs), go to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead
of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use
that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a
reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get
an
error
message
when trying to add a UserForm, try to add the reference
to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't
find
the
file,
then
you'll probably want to run "Detect And Repair" from the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing
FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson





  #36   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Tom Thank you,
I ran it and it ran to the first msgbox and then displayed the first file
name. WHen I selected ok it errored out again with the 1004 error and the
debug highlighted this area of code
Set wb = Workbooks.Open(list(i))

Any help??
BOb

"Tom Ogilvy" wrote in message
...
Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy



"rjr" wrote in message
.. .
Gary my apologies, I used your code as a standalone and the first loop
worked fine and opened the first file, but when it did the loop errored
out as did Otto's, on the second round. This is the same thing that
happened with Otto's code and does it consistentantly with my desktop and
my laptop.

I'm sorry for not getting back with you on this. Can you think of a
reason your 2003 would work and mine wouldn't?
Bob Reynolds


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition
with all current updates and a valid updated Office Professional
product.
As a side note I've also placed it on my Dell D520 laptop with Windoes
XP Professional and Office 2003 with the exact same results. Since it
works for everyone else it obviously has to be something with my
computers, but WHAT? My dell laptop is relatively clean without a lot
of additional programs and the results are the same. That's why I think
the problem lies with my machine's setup...

Bob R

"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


















  #37   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy

"rjr" wrote in message
. ..
Dave, my apologies for not getting back sooner, kinda forgot where I'm at
.

Yes I tried the subroutine you provided
Option Explicit
Sub Testme01()
Dim myName As String
Dim wb As Workbook
myName = "C:\Documents and Settings\Owner\Desktop\KathleenFolder\asf.xls"

Set wb = Workbooks.Open(myName)
End Sub

and it worked fine. I changed the my name to c:\temp which is where we
we're now working out of. It seems the problem occurs when the code loops
and it won't open the second file as it did the first. I am able to open
all the files in that folder individually, but not through the code. I
also tried Gary's little routine that worked on 2003 and it stopped at the
same location as Otto's code did.
Is that a setting that might be creating problems for me inside of 2003?

Thanks again
Bob Reynolds
"Dave Peterson" wrote in message
...
First, did you try that little subroutine?

Otto posted this code as the basis for the code you're using.

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 Sub

This could cause trouble if the logged drive isn't the C: drive.
(Changing the
folder won't change the drive.)

Does adding another line help?

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
ChDrive myPath '<--- Added
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub

rjr wrote:

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP
Media
Edition 2005. I can't get it to work on my computer at all, so I thought
I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop.
She is
running Windows XP Home and Office 2000 Professional and consequently
Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible
or
is there an issue with 2003 that needs to be turned on to make them
work.?
I really need to make this work on an Excel 2003 program so I'm kinda
back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem, especially
on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a replacement
for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file.
***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of
.xls
files and open, do the procedure and then close -- move to next one
and
redo
the procedure until all files (approx 22) have had the code run on
them
and
it's completed.

I will add that if I take this portion (where the error occurs) of
the
code
out of it, the code runs perfectly on each file operated
independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through
the
loop he hangs up right there. Otto has it working fine (With the same
files)
on his computer and I even transferred all my miles and code to
another
laptop I have running windows xp pro and office 2003 with the same
exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't see
where
it would since all features are installed, but I don't know enough to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the
file
that
was the first one to be opened. Would a new installation of Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox
showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory
that
we're
using as the directory and the proper file name. It still
errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and
his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls" Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't
actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work,
but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in message
. ..
Run Time Error 1004 Method OPEN of object.workbooks failed.
This
is
in
the Microsoft vb alert window. the Error place in the code
is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls"
Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" &
TheFile) <<
error
line.

I've sent Otto the files while he was working on the code.
The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on
the
file.



"Dave Peterson" wrote in message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you
don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with.
I've
done
a
complete
detect and repair and as Chip has suggested I've looked in
the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible. I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the
problem.
The
code
performs as it should on his machine and completes. I
still
get
the
error
and the code stops, as Otto has said. Is there anything
that
anyone
can
think of that I can do that he and I haven't. If
uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is
it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library". He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it
should
be
present
in
the list. MSFORMS is part of the basic Excel
installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library" doesn't
appear
at
all in
the References list, the basic installation of Excel is
bad.

The first thing I'd advise to your user is to unregister
and
re-register
Excel. Close Excel (and all other Office programs), go
to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead
of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use
that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a
reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get
an
error
message
when trying to add a UserForm, try to add the reference
to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't
find
the
file,
then
you'll probably want to run "Detect And Repair" from the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing
FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson

--

Dave Peterson


--

Dave Peterson





  #38   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

Got the runtime error 1004 method open of object workbooks failed with the
debug
showing
Set wb = Workbooks.Open(list(i))

Bob
"Tom Ogilvy" wrote in message
...
Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy

"rjr" wrote in message
. ..
Dave, my apologies for not getting back sooner, kinda forgot where I'm at
.

Yes I tried the subroutine you provided
Option Explicit
Sub Testme01()
Dim myName As String
Dim wb As Workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

Set wb = Workbooks.Open(myName)
End Sub

and it worked fine. I changed the my name to c:\temp which is where we
we're now working out of. It seems the problem occurs when the code loops
and it won't open the second file as it did the first. I am able to open
all the files in that folder individually, but not through the code. I
also tried Gary's little routine that worked on 2003 and it stopped at
the same location as Otto's code did.
Is that a setting that might be creating problems for me inside of 2003?

Thanks again
Bob Reynolds
"Dave Peterson" wrote in message
...
First, did you try that little subroutine?

Otto posted this code as the basis for the code you're using.

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 Sub

This could cause trouble if the logged drive isn't the C: drive.
(Changing the
folder won't change the drive.)

Does adding another line help?

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
ChDrive myPath '<--- Added
TheFile = Dir("*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir
Loop
End Sub

rjr wrote:

Latest Update.
Otto and I worked and worked and discovered he is using Excel 2002
Professional and I am using Excel 2003 Professional with Windows XP
Media
Edition 2005. I can't get it to work on my computer at all, so I
thought I'd
try my laptop which is new and has Excel 2003 Professional, along with
Windows XP Professional also. Then I decided to try my wife's laptop.
She is
running Windows XP Home and Office 2000 Professional and consequently
Excel
2000 Professional.

Lo and Behold the code ran correctly and did exactly what Otto swore it
would do and did on his computer.
Now my question is does anyone know of a reason this should be possible
or
is there an issue with 2003 that needs to be turned on to make them
work.?
I really need to make this work on an Excel 2003 program so I'm kinda
back
where I was.....
Any advice would be greatly appreciated and I would also like to thank
everyone that helped in gaining resolution with this problem,
especially on
New Year's Eve.

Bob Reynolds
"Dave Peterson" wrote in message
...
I wanted you to try the separate procedure as a test--not a
replacement for
the
original procedure.

And I can't think of any other reasons--and I wouldn't guess that
reinstalling
Office (or windows!) would help--but I've been wrong lots of times.



rjr wrote:

"Dave Peterson" wrote in message
...
I wouldn't guess so--but that's just a guess.

I'm still guessing that it's something simple--like a locked file.
***
none of the files are locked or protected.

If you create a separate procedure in a test module:

*****No because what we're trying to do is go down the directory of
.xls
files and open, do the procedure and then close -- move to next one
and
redo
the procedure until all files (approx 22) have had the code run on
them
and
it's completed.

I will add that if I take this portion (where the error occurs) of
the
code
out of it, the code runs perfectly on each file operated
independently
but
it requires me to run it on each one individually.

Option Explicit
sub Testme01()
dim myName as string
dim wb as workbook
myName = "C:\Documents and
Settings\Owner\Desktop\KathleenFolder\asf.xls"

set wb = workbooks.open(myname)
End sub

===
I don't think that this will help...

But if you move that asf.xls file to a different location, does
the
original
procedure work ok?

I can't imagine what can be happening where you can open this file
manually, but
have problems when you open it via code.

It will open by single code, like I said, but once we try it through
the
loop he hangs up right there. Otto has it working fine (With the
same
files)
on his computer and I even transferred all my miles and code to
another
laptop I have running windows xp pro and office 2003 with the same
exact
results I get. That's why I was thinking it might be a setting on my
computer...Again, if it works on other computers that would tend to
isolate
mine as the cause. Is there any reasons that you can think of.....
Lastly
do you think removing and reinstalling office would help. I can't
see
where
it would since all features are installed, but I don't know enough
to
make a
really educated guess....

Thanks
Bob Reynolds

rjr wrote:

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

This is the location of where the file is and the asf.xls is the
file
that
was the first one to be opened. Would a new installation of
Office
Professional help, do you think???
Bob

"Dave Peterson" wrote in message
...
I don't have a guess, but I am curious about what the msgbox
showed.

What was the filename (or path and filename)?

rjr wrote:

I put Tom's in and the msgbox returned the complete directory
that
we're
using as the directory and the proper file name. It still
errored
out
on
the
Set wb line...
I'm thinking that it has to do with some setting I've got on
my
computer
that's keeping this from running.
Otto had run it two different ways and also used my file and
his
ran
perfectly, but I've continued getting the error.

Bob
"Tom Ogilvy" wrote in message
...
Here is another guess -

Change the code to:

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls"
Then
MsgBox ThePath & "\" & TheFile
Set wb = Workbooks.Open(ThePath & "\" & TheFile)


make sure you actually need to append the "\" and don't
actually
have
a
filename result like:

C:\\Report1.xls

In windows NT type Operating systems, this will still work,
but
in
Windows
9x, it will error.



--
Regards,
Tom Ogilvy



"rjr" wrote in
message
. ..
Run Time Error 1004 Method OPEN of object.workbooks
failed.
This
is
in
the Microsoft vb alert window. the Error place in the code
is at

Do While TheFile < ""
If TheFile < "Daily Error report MASTER.xls"
Then
MsgBox TheFile
Set wb = Workbooks.Open(ThePath & "\" &
TheFile) <<
error
line.

I've sent Otto the files while he was working on the code.
The
code
works
perfectly for him at his computer.
I can open ALL files from file open or double clicking on
the
file.



"Dave Peterson" wrote in
message
...
What's the error that is displayed?

Any chance that Otto has access to that folder and you
don't?

Can you open the file just via File|Open?

rjr wrote:

Hi, I've got the problem that Otto is helping me with.
I've
done
a
complete
detect and repair and as Chip has suggested I've looked
in the
References
List box and I do have Microsoft Forms 2.0 Object Library
installed
and
checked. I also have the FM20.dll installed and visible.
I
also
attempted to
include a user form and it was installed without a hitch,
absolutely
no
problem.

I did send the file to Otto and he can't recreate the
problem.
The
code
performs as it should on his machine and completes. I
still
get
the
error
and the code stops, as Otto has said. Is there anything
that
anyone
can
think of that I can do that he and I haven't. If
uninstalling
and
reinstalling Excel would work I could do that also.

Thanks Bob Reynolds

"Chip Pearson" wrote in message
...
Do you know the exact wording of the error message? Is
it
coming
from
Excel or from VBA?

he doesn't is "Microsoft Forms 2.0 Object Library".
He
doesn't
have
anything like that to check.

That's a big clue. Does he really not have the Forms
library
listed
in
the References list box? Even if it not checked, it
should
be
present
in
the list. MSFORMS is part of the basic Excel
installation,
not
optional in
any way. If "Microsoft Forms 2.0 Object Library"
doesn't
appear
at
all in
the References list, the basic installation of Excel is
bad.

The first thing I'd advise to your user is to
unregister and
re-register
Excel. Close Excel (and all other Office programs), go
to
the
Windows
Start menu, choose Run and enter

RegSvr32 "Excel.exe" /unregserver

The repeat the process with

RegSvr32 "Excel.exe" /regserver

You may have to use the full file path of Excel instead
of
just
"Excel.exe". In the Immediate window of VBA, enter the
following
and
press
Enter.

?Application.Path & "\Excel.exe"

This will display the full pathname of Excel.exe. Use
that
filename
in
place of "Excel.exe" in the RegSvr32 commands.

Now try to open the workbook. In VBA, ensure that
"Microsoft
Forms
2.0
Object Library" appears in the list of references. Try
adding
a
UserForm
to the project. Doing so will automatically add a
reference
to
MSFORMS.

If this fails, and you (by which I mean your user) get
an
error
message
when trying to add a UserForm, try to add the reference
to
MSFORMS
manually. In the References dialog, click "Browse" and
navigate
to
the
file

C:\WINDOWS\system32\FM20.DLL

If you find the file, click OK or Open. If you don't
find
the
file,
then
you'll probably want to run "Detect And Repair" from
the
Help
menu.
If
this doesn't fix the problem, you'll likely need to
uninstall
and
reinstall Office.

A missing MSFORMS reference item and/or a missing
FM20.DLL
file
indicates
that something serious has gone on.


--
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
...
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





--

Dave Peterson

--

Dave Peterson

--

Dave Peterson

--

Dave Peterson







  #39   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Code looping through files

That eliminates using the DIR command as a possible source of the problem.

Since the problem is in xl2003, then perhaps:

In excel I would go to Tools=About Microsoft Excel, then look in Disabled
Items button at the bottom. If any of your files are listed there, then I
would remove them from being disabled (select the appropriate files one at a
time in the list and hit the Enable button for each).

You said you had opened them manually, but that may have been sometime in
the past.

--
Regards,
Tom Ogilvy



"rjr" wrote in message
...
Tom Thank you,
I ran it and it ran to the first msgbox and then displayed the first file
name. WHen I selected ok it errored out again with the 1004 error and the
debug highlighted this area of code
Set wb = Workbooks.Open(list(i))

Any help??
BOb

"Tom Ogilvy" wrote in message
...
Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy



"rjr" wrote in message
.. .
Gary my apologies, I used your code as a standalone and the first loop
worked fine and opened the first file, but when it did the loop errored
out as did Otto's, on the second round. This is the same thing that
happened with Otto's code and does it consistentantly with my desktop
and my laptop.

I'm sorry for not getting back with you on this. Can you think of a
reason your 2003 would work and mine wouldn't?
Bob Reynolds


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition
with all current updates and a valid updated Office Professional
product.
As a side note I've also placed it on my Dell D520 laptop with Windoes
XP Professional and Office 2003 with the exact same results. Since it
works for everyone else it obviously has to be something with my
computers, but WHAT? My dell laptop is relatively clean without a lot
of additional programs and the results are the same. That's why I
think the problem lies with my machine's setup...

Bob R

"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




















  #40   Report Post  
Posted to microsoft.public.excel.programming
rjr rjr is offline
external usenet poster
 
Posts: 50
Default Code looping through files

No disabled items found.
Opened them manually as late as this evening. I've opened them without issue
at least 15 times today.

Bob

"Tom Ogilvy" wrote in message
...
That eliminates using the DIR command as a possible source of the problem.

Since the problem is in xl2003, then perhaps:

In excel I would go to Tools=About Microsoft Excel, then look in Disabled
Items button at the bottom. If any of your files are listed there, then I
would remove them from being disabled (select the appropriate files one at
a time in the list and hit the Enable button for each).

You said you had opened them manually, but that may have been sometime in
the past.

--
Regards,
Tom Ogilvy



"rjr" wrote in message
...
Tom Thank you,
I ran it and it ran to the first msgbox and then displayed the first file
name. WHen I selected ok it errored out again with the 1004 error and the
debug highlighted this area of code
Set wb = Workbooks.Open(list(i))

Any help??
BOb

"Tom Ogilvy" wrote in message
...
Try it like this

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
Dim list() As String
Dim i As Long
ReDim list(1 To 1)
MyPath = "C:\Temp"
ChDrive MyPath
ChDir MyPath
TheFile = Dir("*.xls")
Do While TheFile < ""
list(UBound(list)) = MyPath & "\" & TheFile
ReDim Preserve list(1 To UBound(list) + 1)
TheFile = Dir
Loop
ReDim Preserve list(1 To UBound(list) - 1)
For i = 1 To UBound(list)
Set wb = Workbooks.Open(list(i))
MsgBox wb.FullName
wb.Close
Next i
End Sub

--
Regards,
Tom Ogilvy



"rjr" wrote in message
.. .
Gary my apologies, I used your code as a standalone and the first loop
worked fine and opened the first file, but when it did the loop errored
out as did Otto's, on the second round. This is the same thing that
happened with Otto's code and does it consistentantly with my desktop
and my laptop.

I'm sorry for not getting back with you on this. Can you think of a
reason your 2003 would work and mine wouldn't?
Bob Reynolds


"Gary Keramidas" <GKeramidasATmsn.com wrote in message
...
this works for me

Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
TheFile = Dir(MyPath & "\" & "*.xls")
Do While TheFile < ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
MsgBox wb.FullName
wb.Close
TheFile = Dir()
Loop
End Sub

--


Gary


"rjr" wrote in message
.. .
Hello again to all,
I wish it were that simple. Nope I'm windows XP Media Center Edition
with all current updates and a valid updated Office Professional
product.
As a side note I've also placed it on my Dell D520 laptop with
Windoes XP Professional and Office 2003 with the exact same results.
Since it works for everyone else it obviously has to be something
with my computers, but WHAT? My dell laptop is relatively clean
without a lot of additional programs and the results are the same.
That's why I think the problem lies with my machine's setup...

Bob R

"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






















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
Looping thru Files In FolderSub Jim May Excel Programming 4 August 2nd 06 11:49 PM
Looping through excel files to add to a new workbook Geoff Excel Programming 8 April 29th 06 11:54 AM
Looping through files in a folder prepotency[_12_] Excel Programming 1 July 13th 05 04:23 PM
Looping thru files extracting data gtslabs[_2_] Excel Programming 3 June 3rd 05 04:22 PM
Looping thru files Tom Excel Programming 4 January 9th 04 05:05 PM


All times are GMT +1. The time now is 04:47 PM.

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

About Us

"It's about Microsoft Excel"