View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Workbook.Open fail in 2003, good in XP

Dave
That didn't do anything with the problem. I include the code below.
The OP's computer errors out on the Open line and mine doesn't (my system
opens the file). Thanks again. Otto
Sub testopen()
ThePath = "C:\Temp\"
ChDrive ThePath
ChDir ThePath
TheFile = Dir("*.csv")
Application.DisplayAlerts = False
Set wb = Workbooks.Open(ThePath & TheFile)
Application.DisplayAlerts = True
End Sub
"Dave Peterson" wrote in message
...
Changing the directory doesn't change the drive.

I'd change the drive, too:

chdrive ThePath
chdir thepath

=====
And what's the name of the .csv file and the name of the .xls file?



Otto Moehrbach wrote:

Excel XP & Win XP
I'm helping an OP. He has Excel 2003 Pro.
He and I have now run the code shown below several times on both our
computers. His computer fails on the "Set wb = Workbooks.Open.........."
line every time.
Note that the code is looking for a .csv file. The Temp folder has a
bunch
of those. It also has one .xls file. We both changed the ".csv" to
".xls"
in the below code and ran the code again.
In ALL cases, the file opens on my computer and NEVER opens on his.
The error is always on the "Set wb..." line.
My question: Why does this code fail on his computer and not on mine?
Thanks for your time. Otto
Sub testopen()
ThePath = "C:\Temp\"
ChDir ThePath
TheFile = Dir("*.csv")
Application.DisplayAlerts = False
Set wb = Workbooks.Open(ThePath & TheFile)
Application.DisplayAlerts = True
End Sub
PS: I sent him the entire file, so it's not a case of copy/paste.


--

Dave Peterson