Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default cannot close workbook

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default cannot close workbook

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.



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



.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default cannot close workbook

Chris,

Please supply a short but complete sub procedure of sample code that illustrates your problem. The sub should show how you open the
workbook and then close it. Something like the following:

Sub Test()
Dim w(1 To 3) As Workbook

Set w(2) = Workbooks.Open(Filename:="C:\Data.xls")
w(2).Sheets(1).Range("A1").Value = 10
w(2).Close SaveChanges:=False
End Sub


--

John Green - Excel MVP
Sydney
Australia


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



.



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
Close Workbook in Excel Brenda from Michigan[_2_] Excel Discussion (Misc queries) 3 February 6th 09 06:32 PM
close a workbook after 5 minutes Marilyn Excel Discussion (Misc queries) 15 September 18th 08 08:44 PM
workbook before close mohavv Excel Discussion (Misc queries) 2 November 21st 07 01:27 AM
close only one workbook bobsmom70601 New Users to Excel 1 March 8th 05 09:43 PM
How can I close only 1 workbook when I have many open? jpt consulting Excel Discussion (Misc queries) 3 November 30th 04 11:58 PM


All times are GMT +1. The time now is 09:11 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"