Save in VBA?

T

TJ

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,
 
T

TJ

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,
 
C

Chip Pearson

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top