Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default BeforeSave sub won't save another workbook when triggered by another event sub

If a BeforeSave sub in Book2.xls contains a statement to
save Book1.xls, both workbooks are saved when you save
Book2.xls

If Book2.xls is saved by a BeforeClose sub (for
Book2.xls), however, then Book1.xls is not saved.

'code in Book1.xls ThisWorkbook code pane
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
End Sub

'code in Book2.xls ThisWorkbook code pane
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeClose"
ThisWorkbook.Saved = True
ThisWorkbook.Save
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
Workbooks("Book1.xls").Save
End Sub

My workaround for the problem is to save Book1.xls in
both the BeforeClose and BeforeSave subs. But the code
posted ought to work.

If it matters, I'm using Excel 2003 (11.6113.5703).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default BeforeSave sub won't save another workbook when triggered by anotherevent sub

It didn't work for me in xl2002, either.

But this did:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
Application.Run "Book1.xls!thisworkbook.workbook_beforeSave", False, False
End Sub

(everything else the same)

Another alternative. Put a macro in a general module in book1.xls.

Option Explicit
Sub savemenow()
ThisWorkbook.Save
End Sub

Then this worked, too.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
Application.Run "book1.xls!SaveMeNow"
End Sub

Brad Yundt wrote:

If a BeforeSave sub in Book2.xls contains a statement to
save Book1.xls, both workbooks are saved when you save
Book2.xls

If Book2.xls is saved by a BeforeClose sub (for
Book2.xls), however, then Book1.xls is not saved.

'code in Book1.xls ThisWorkbook code pane
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
End Sub

'code in Book2.xls ThisWorkbook code pane
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeClose"
ThisWorkbook.Saved = True
ThisWorkbook.Save
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox Me.Name & " Workbook_BeforeSave"
Workbooks("Book1.xls").Save
End Sub

My workaround for the problem is to save Book1.xls in
both the BeforeClose and BeforeSave subs. But the code
posted ought to work.

If it matters, I'm using Excel 2003 (11.6113.5703).


--

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
BeforeSave event Carl Bowman Excel Discussion (Misc queries) 4 February 6th 05 12:28 PM
BeforeSave event j23 Excel Programming 0 April 6th 04 11:15 AM
BeforeSave workbook event Cindy Excel Programming 15 February 10th 04 04:28 PM
Is this an Excel workbook event triggered AFTER saving Lee Drage[_2_] Excel Programming 3 January 29th 04 08:11 AM
Help - Change Event triggered on File Save As Dee Veloper Excel Programming 4 October 29th 03 02:16 AM


All times are GMT +1. The time now is 10:32 PM.

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"