Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Problem with Workbook_BeforeSave event

Hi all.

I have noticed that Workbook_BeforeSave event does not work properly
if the workbook is closed by a VBA macro of another workbook or by an
external VB program.

For example, suppose I have the following two simple event procedures
in ThisWorkbook module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
MsgBox("BeforeSave event triggered")
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Do something processing here such as hide certain worksheets and
protect the workbook
MsgBox("Before Me.Save")
Me.Save
MsgBox("After Me.Save")
End Sub

If I close the workbook manually in Excel, I would see the all three
MsgBox displays and the worksheets I specified in the code would be
hidden in the saved file.

Now, suppose I have created an external VB program containing the
following codes:

Sub Main()
Dim xlApp as Object
Dim xlWorkbook as Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Open FileName:="SomeTestFile.xls"
Set xlWorkbook = xlApp.Workbooks(1)
xlWorkbook.Close
xlApp.Close
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub

This simple program is supposed to create an Excel application object,
open a workbook, and then close the workbook. I was expecting all
workbook events procedures would run as if I opened and closed the
workbook manually.

However, when I run the program, I only see "Before Me.Save" and
"After Me.Save" msgboxes displayed. I did not see "BeforeSave event
triggered" message displayed so that implies the BeforeSaveEvent was
never triggerd. And afterward, Excel would display the "Do You want
to save changes made in the workbook" message. If I select Yes to
save the changes, worksheets that should have been hidden
Workbook_BeforeClose proecdure are still visible in the saved file.

Does anyone know if there is any known problem with
Workbook_BeforeClose event procedure?

Thanks.
Jason

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
HELP!!!! Calling a sub from Workbook_BeforeSave RocketMan[_2_] Excel Discussion (Misc queries) 4 May 31st 07 11:47 PM
Workbook_BeforeSave() bmm Excel Programming 3 August 16th 04 03:37 PM
Workbook_Beforesave getting breached Hari[_3_] Excel Programming 2 June 11th 04 10:57 PM
Workbook_BeforeSave Bill Oertell Excel Programming 5 December 21st 03 07:33 PM
Workbook_BeforeSave() in xla Bent Kjeldsen Excel Programming 6 September 24th 03 01:49 PM


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