trap save events in Word and Excel

A

arno

Hi,

I've been asked to develop the following: devise a way to trap Save
events of both Word documents and Excel workbooks, and check if they
have a set of custom document properties filled out.

There are several ways I can go about this:

1. incorporate a piece of VBA code into every new template that checks
for this (very easy)
2. write 2 'global templates' for both Word and Excel that does the
same. (easy)
3. As DocumentProperties are an Office-wide feature, write an Add-in
that does that for me, from 1 place and 1 file. (not as easy as I had
hoped)

I am okay with VBA and VB, but writing Office Add-Ins is new to me. So
far, I got as far as trapping the NewWorkbook and WorkbookOpen event
in Excel. How do I trap the BeforeSave event? Excel has it, Word
doesnt it seems.

So, if you'll bear with me please, a few questions:
-how do I trap the Save 'document' (workbook and document) events for
Excel and Word?
-Is an Add-In the way to go?
-I am on VB6/Office2000, how hard will it be to be to migrate my
solution -if ever I get there- to Office 2003?

tia
arno
 
X

XL-Dennis

Hi arno,

I'm not so good when it comes to MS Word but I can give You some input that
hopefully gets You on the right track here.

If I understand You correctly You already knows how to deal with Excel's
events but not with Word's event. I'm not sure on how to approach it so I
hope other frequent posters here can shed some light over it.

If You add-in is general to some degree then the answer is yes.Since You
target two Office-softwares it's from my point of view a reasonable approach.
The major advantage is that You need only to maintain one version.

Not at all, actually this is the best scenario as the solution will be
forward compatible. It will also work with Office 2007.

Check out Ken Slovak's online chapter about COM Add-ins.
http://www.slovaktech.com/Files/3315_Chapter07.pdf

You may also check out the following article:
http://www.thecodenet.com/articles.php?id=38&PHPSESSID=c49c197ce4660c543333ce9547c239de

For a discussion about Early vs Late binding check out:
http://www.thecodenet.com/articles.php?id=11&PHPSESSID=c49c197ce4660c543333ce9547c239de

Let us know how it progress.

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site: http://www.xldennis.com/
 
P

pavan

Hi
It's pretty simple to trap the document before save event in word.

wdApp = (Microsoft.Office.Interop.Word.Applcation)application;
wdApp.DocumentBeforeSave+=new
Microsoft.Office.Interop.Word.ApplcationEvents4_DocumentChangeEventHandler(wdApp
_BeforeSave);

If you are using Word 2003 and above this should as it is work for you,
where wdApp is your word application object. For Word XP, change
ApplcationEvents4 to ApplcationEvents3. That should work. I guess for
Word 2000 it is 2.

Hope this helps,
Pavan
 
P

pavan

Small error....changing "Change" to "DocumentBeforeSave"
wdApp.DocumentBeforeSave+=new
Microsoft.Office.Interop.Word.ApplcationEvents4_DocumentDocumentBeforeSaveEventHandler(­wdApp

_BeforeSave);
 

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