problem with DocumentBeforeSave

O

Omega

Hi!

I am new user to COM objects, so sorry if the questions are easy, I tried
googling it, but I didn't find the answer, so I ask you:

I am writing an application. I open word document from it, sometimes the
document exists, sometimes I want to open new document in word. So far I
opened word and I handle DocumentBeforeSave event. I have still got three
problems:

1) I would like to only catch Save and SaveAs events, not AutoSave, but
from what I noticed DocumentBeforeSave catches all three of them. Can I
somehow switch off the autoSave, or tell which one of these events caused
the DocumentBeforeSave event?

2) I would like to prevent the document from saving after
DocumentBeforeSave event is handled. I tried setting Cancel to true and
SaveAsUI to false, but it does not seem to work. I read somewhere, that
"Cancel = true;" should be the last operation in handling methos, or that I
should call "return;" or "Exit Sub;" in VB to prevent document from saving.

3) While the Word application is opened, my main application is still
running. After each save in word, I would like to refresh some components
on my main frame. Now it doesn't work, I get exceptions in OnPaint event. I
know that Word is opened in new thread, can it be the reason, why
refreshing does not work? How can I make it work?

I will be gratefull for any answers, links to some useful articles etc.

Omega
 
C

Cindy M.

Hi Omega,

Note that this newsgroup is for VBA questions; your question apparently
concerns using VB.NET. The better place to ask your questions would be the
word.programming or the office.developer.automation newsgroup.
1) I would like to only catch Save and SaveAs events, not AutoSave, but
from what I noticed DocumentBeforeSave catches all three of them. Can I
somehow switch off the autoSave, or tell which one of these events caused
the DocumentBeforeSave event?
Unfortunately, no, there's no way to distinguish this. You can turn off
AutoSave, but this is application-wide, which means it could be very dangerous
for the user if he's working on multiple documents! And you'd certainly have
to be very sure it's turned back on. Look up the SaveInterval property in the
object model Help.
2) I would like to prevent the document from saving after
DocumentBeforeSave event is handled. I tried setting Cancel to true and
SaveAsUI to false, but it does not seem to work. I read somewhere, that
"Cancel = true;" should be the last operation in handling methos, or that I
should call "return;" or "Exit Sub;" in VB to prevent document from saving.
In my experience, this does work. Hard to advise you further without more
information about HOW it doesn't work, and without seeing your code.
3) While the Word application is opened, my main application is still
running. After each save in word, I would like to refresh some components
on my main frame. Now it doesn't work, I get exceptions in OnPaint event. I
know that Word is opened in new thread, can it be the reason, why
refreshing does not work? How can I make it work?
Again, there's insufficient information. Since you're capturing the event in
your code, and therefore in the same thread, I can't imagine Word being the
*direct* problem, unless you're doing something with the Windows API. This
question you may need to take to a VB.NET newsgroup or forum, however.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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