Discussion:
BUG on Framework??
(too old to reply)
dev
2007-09-14 22:34:02 UTC
Permalink
hi to all, I have an issue with a feature of an addin.

I did a simple word add-in that catch the "Save" event and the "Print" event.
When the addin catchs these events, it must show a simple MSGBOX ("bye") and
MSWord doesn't save or print the active document.

For do that, I used a object word and catch the event "documentBeforeSave"
and "documentBeforePrint" and I see on the MSDN that If I set a Cancel
variable to TRUE the active document doesn't saved.

The problem is If I set Cancel variable to TRUE, the document will be saved
anyway!

What is the problem? there is a bug in the framework, or I'm not using it in
the right way?

thank you!
Russ
2007-09-15 17:55:33 UTC
Permalink
Hi dev,
It looks like you got your information from a page like this:
<http://msdn2.microsoft.com/en-us/library/aa263710(office.10).aspx>
Did you follow the link on that page to and create a *class* module?:
<http://msdn2.microsoft.com/en-us/library/aa263743(office.10).aspx>

Anyway, here is more info using Word VBA:
<http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm>
Post by dev
hi to all, I have an issue with a feature of an addin.
I did a simple word add-in that catch the "Save" event and the "Print" event.
When the addin catchs these events, it must show a simple MSGBOX ("bye") and
MSWord doesn't save or print the active document.
For do that, I used a object word and catch the event "documentBeforeSave"
and "documentBeforePrint" and I see on the MSDN that If I set a Cancel
variable to TRUE the active document doesn't saved.
The problem is If I set Cancel variable to TRUE, the document will be saved
anyway!
What is the problem? there is a bug in the framework, or I'm not using it in
the right way?
thank you!
--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
dev
2007-09-16 22:50:03 UTC
Permalink
Hi Russ! Thank you very much for the help.

I'm studying the links you showing me, but the code that I'm reading in the
second link, doesn't works:
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub

I'm developing an Word Addin using VB .NET and the "Set" keyword, doesn't
exists; when I paste that code in the developing enviroment, the "Set"
keyword disappear, I'm developing a word addin, maybe that code refers to VBA
language.

Anyway,
this is the code I've put in the DocumentBeforePrint Sub in my Word Addin:

Try

MsgBox("Hello World!")
Cancel = True

Catch ex As Exception
MsgBox(ex.ToString)
End Try

I set "Cancel" to TRUE becouse I read this:

Cancel- False when the event occurs. If the event procedure sets this
argument to True, the document isn't printed when the procedure is finished.

So I think I should see the MSGBOX "HelloWorld" and I can't see the window
for Print the Document...it's not true! I can see the MSGBOX and I can see
the window for Print and I can print the active document.

Have you a workaround for my problem?

thank you
Russ
2007-09-17 17:44:04 UTC
Permalink
Dev,
Sorry, I know nothing about VB .NET coding. I can only offer some info on
VBA code. You might be able to study VBA code to get an idea about code to
use, but it will be up to you to translate that code to VB .NET.
For example, if you start Word and press ALT F11, it will bring up the Word
VBA Editor. Use the help menu and type in the word 'set' to see what it does
in VBA. Then decide what you would use in VB .NET for doing the same thing.
And of course Google knows everything:
<http://www.google.com/search?&q=%22vb%20.net%22+vba>

We are mostly volunteers in this forum offering info and the forum deals
with word VBA. I suggest you look for a VB .NET forum for more germane
suggestions.
Post by dev
Hi Russ! Thank you very much for the help.
I'm studying the links you showing me, but the code that I'm reading in the
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.App = Word.Application
End Sub
I'm developing an Word Addin using VB .NET and the "Set" keyword, doesn't
exists; when I paste that code in the developing enviroment, the "Set"
keyword disappear, I'm developing a word addin, maybe that code refers to VBA
language.
Anyway,
Try
MsgBox("Hello World!")
Cancel = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Cancel- False when the event occurs. If the event procedure sets this
argument to True, the document isn't printed when the procedure is finished.
So I think I should see the MSGBOX "HelloWorld" and I can't see the window
for Print the Document...it's not true! I can see the MSGBOX and I can see
the window for Print and I can print the active document.
Have you a workaround for my problem?
thank you
--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID
dev
2007-09-17 23:54:01 UTC
Permalink
OK Russ, thank u very much anyway.

bye
Daryl
2007-11-28 01:49:00 UTC
Permalink
Hi dev,

Just wondering if you got this to work? I've just started writing a Word
Add-in in VB.Net and have got this to work if you still need a hand.
Loading...