View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default cannot close workbook

workbooks("W(2).xls").close SaveChanges:=False

should work if it actually has that name. If you get subscript out of
range, then you don't have a workbook open that has a name of W(2).xls.

Regards,
Tom Ogilvy

chris neill wrote in message
...
John,
Many thanks but it didn't work!
The workbook is saved as "W(2).xls".
I've tried using Windows("W(2).xls").Close
SaveChanges:=False
as this worked ok with another macro but it doesn't work
here!
Any further ideas?
Chris

-----Original Message-----
If the workbook is saved with the file name W(2).xls use:

WorkBooks("W(2).xls").Close SaveChanges:=False

If W is an object variable array use:

W(2).Close SaveChanges:=False

--

John Green - Excel MVP
Sydney
Australia


"chrisneill" wrote in message

...
Can somebody pse help me with this one.

I have 3 workbooks open. W(1) has the VBA code to copy
data from W(2) to W(3).

W(2) & W (3) are opened with:-

Workbooks.Open Filename:=" address "

do stuff

I then want to close W(2) and not to save but

Workbooks("W(2) Name").Activate
ActiveWorkbook.Close SaveChanges:=False .....Fails here

& keeps returning Error 9 - "Subscript out of range"
Can someone pse help me?
Thankyou.



.