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

i have put the following code in to workbook 'A' to close workbook 'B' but it
does not close book 'B' there is no error message

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default automatically close second workbook

Several of us have tested your code..........both workbook_open which opens
B.xls when A.xls opens and the workbook_beforeclose code.

Works fine for me.

All I can think of is that you are opening B.xls in a separate instance of
Excel.

If that's the case, the beforeclose code in A.xls will not trigger B.xls to
close.

Try this code in A.xls

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
Application.Quit
End Sub

Do you still have workbook B.xls open in an instance of Excel?


Gord Dibben MS Excel MVP

On Wed, 16 Dec 2009 12:29:02 -0800, uk
wrote:

i have put the following code in to workbook 'A' to close workbook 'B' but it
does not close book 'B' there is no error message

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default automatically close second workbook

Gord,

The last time this poster had problems like this, it was because the extension
of the file wasn't .xls. It was .xlsm or .xlsx or .xlsb or who knows what.



Gord Dibben wrote:

Several of us have tested your code..........both workbook_open which opens
B.xls when A.xls opens and the workbook_beforeclose code.

Works fine for me.

All I can think of is that you are opening B.xls in a separate instance of
Excel.

If that's the case, the beforeclose code in A.xls will not trigger B.xls to
close.

Try this code in A.xls

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
Application.Quit
End Sub

Do you still have workbook B.xls open in an instance of Excel?

Gord Dibben MS Excel MVP

On Wed, 16 Dec 2009 12:29:02 -0800, uk
wrote:

i have put the following code in to workbook 'A' to close workbook 'B' but it
does not close book 'B' there is no error message

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default automatically close second workbook

I seem to remember something like that but OP did state at that time B.xls
did open when he opened A.xls

So..........maybe the extension was correct in the open code but not in the
beforeclose code?


Gord


On Wed, 16 Dec 2009 16:41:13 -0600, Dave Peterson
wrote:

Gord,

The last time this poster had problems like this, it was because the extension
of the file wasn't .xls. It was .xlsm or .xlsx or .xlsb or who knows what.



Gord Dibben wrote:

Several of us have tested your code..........both workbook_open which opens
B.xls when A.xls opens and the workbook_beforeclose code.

Works fine for me.

All I can think of is that you are opening B.xls in a separate instance of
Excel.

If that's the case, the beforeclose code in A.xls will not trigger B.xls to
close.

Try this code in A.xls

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
Application.Quit
End Sub

Do you still have workbook B.xls open in an instance of Excel?

Gord Dibben MS Excel MVP

On Wed, 16 Dec 2009 12:29:02 -0800, uk
wrote:

i have put the following code in to workbook 'A' to close workbook 'B' but it
does not close book 'B' there is no error message

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default automatically close second workbook

Or he didn't share the details of the changes that made it work.

(Just my bet.)

Gord Dibben wrote:

I seem to remember something like that but OP did state at that time B.xls
did open when he opened A.xls

So..........maybe the extension was correct in the open code but not in the
beforeclose code?

Gord

On Wed, 16 Dec 2009 16:41:13 -0600, Dave Peterson
wrote:

Gord,

The last time this poster had problems like this, it was because the extension
of the file wasn't .xls. It was .xlsm or .xlsx or .xlsb or who knows what.



Gord Dibben wrote:

Several of us have tested your code..........both workbook_open which opens
B.xls when A.xls opens and the workbook_beforeclose code.

Works fine for me.

All I can think of is that you are opening B.xls in a separate instance of
Excel.

If that's the case, the beforeclose code in A.xls will not trigger B.xls to
close.

Try this code in A.xls

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
Application.Quit
End Sub

Do you still have workbook B.xls open in an instance of Excel?

Gord Dibben MS Excel MVP

On Wed, 16 Dec 2009 12:29:02 -0800, uk
wrote:

i have put the following code in to workbook 'A' to close workbook 'B' but it
does not close book 'B' there is no error message

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Workbooks("B.XLS").Close SaveChanges:=False
ActiveWorkbook.Close SaveChanges:=True
End Sub


--

Dave Peterson
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
automatically close second workbook [email protected] uk Excel Discussion (Misc queries) 2 December 14th 09 10:14 PM
Close form automatically upon opening workbook Ixtreme Excel Discussion (Misc queries) 2 September 18th 09 02:56 PM
Automatically Close Book1 Dave486 Excel Discussion (Misc queries) 0 April 26th 08 11:47 PM
Copy from another file and close automatically Jim G Excel Discussion (Misc queries) 2 October 17th 07 01:31 AM
Close automatically a userform FARAZ QURESHI Excel Discussion (Misc queries) 4 January 7th 07 07:46 PM


All times are GMT +1. The time now is 12:03 AM.

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

About Us

"It's about Microsoft Excel"