Thread: Save in VBA?
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Save in VBA?

To catch events for all open workbooks, you need to use Application
Level events. In a class, use code like

Option Explicit

Private WithEvents XLApp As Excel.Application

Private Sub Class_Initialize()
Set XLApp = Application
End Sub

Private Sub XLApp_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
Debug.Print Wb.Name
End Sub

The terminology will be different in NET, but the concept is the same.
See http://www.cpearson.com/excel/AppEvent.aspx for a discussion of
application events. This page is geared toward VB6/VBA, but it should
be very easy transliterate to NET.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Mon, 27 Oct 2008 18:12:00 -0700, TJ
wrote:

Sorry,

That's not what I wanted to ask..
Actually, I can easily do something thi via BeforeSave event...

What I would like to ask is that...
Once I create .NET standard window .form app....
I am going to load the excel file that is hosted by .NET
In the .NET .form app, is there any way I can catch the Save event?..

I have to try..but I guess .....Excel object may provide some event property
for that......Hum...Anyone?

Also, if I want to create an independent .NET window form app that works
with any version of Excel, I think I have to use late-biding ..right?...
Once I reference the any specific dll for the Excel, then, different version
of excel may not work...

Thanks,



"TJ" wrote:

Hi,

Is there any way I can override the Save in VBA app in Excel?
I meant..when user clicks the save button, I would like to have run
my own business logic, and then save the excel file.

If you know, please share it.

Thanks,