Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
automatically close second workbook | Excel Discussion (Misc queries) | |||
Close form automatically upon opening workbook | Excel Discussion (Misc queries) | |||
Automatically Close Book1 | Excel Discussion (Misc queries) | |||
Copy from another file and close automatically | Excel Discussion (Misc queries) | |||
Close automatically a userform | Excel Discussion (Misc queries) |