Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code no longer works in Excel2003

Status
Not open for further replies.

XB9R

Programmer
Dec 4, 2006
20
BE
I got following code :
Code:
origpad = ThisWorkbook.Path
Workbooks.Open (origpad & "\Myfile2.xls")
[COLOR=red]With Workbooks("Myfile2").Sheets("Data")[/color]
' just doing my stuff here in the Myfile2 workbook
...
End With
Workbooks("Myfile2").Save
Workbooks("Myfile2").Close

Works great in Excel97 but gives error 9 in excel2003 on the red line. All workbooks and sheets exists. (it does open the workbook)

any ideas ?

Dave
 
tried the following

before saving:
?thisworkbook.Name
Book1

after saving:
?thisworkbook.Name
Book1.xls

try
With Workbooks("Myfile2.xls").Sheets("Data")

 
A safer way is to use an object:
Dim objWB As Workbook
Set objWB = Workbooks.Open(origpad & "\Myfile2.xls")
With objWB.Sheets("Data")
' just doing my stuff here in the Myfile2 workbook
...
End With
objWB.Save
objWB.Close
Set objWB = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top