473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Word, DocumentBeforeClose event, unable to Cancel event

AP
Hi,

I'm trying to use c# to pop up a dialog box when a user attempts to close
word to prompt them if they want to exit or cancel (obviously other stuff
needs to happen based on their selection but that's the gist of it.)
I have everything set up, and it seems to work except that setting Cancel to
true and returning from my c# method appears to do nothing. Word still
closes. Am I doing something wrong?

private void wa_DocumentBeforeClose(Document Doc, ref bool Cancel) {
DialogResult dr =

MessageBox.Show("Update Template File on the Server?","Update Template
File",MessageBoxButtons.YesNoCancel,MessageBoxIcon .Question,MessageBoxDefaul
tButton.Button1);
//If they cancel go back to word

if (dr == DialogResult.Cancel) {

Cancel = true;

return;

//word still closes

}

//If they say yes upload to server

if (dr == DialogResult.Yes) {

//do yes stuff

}
//NO - do nothing except

}
Adam
Nov 15 '05 #1
1 8287
ISSUE
=====
You have a VS.NET 2003 application which automates Word.
When you set the Cancel parameter of the
DocumentBeforeClose event it is ignored.

CAUSE
======
The way the interfaces are defined in Word typelibrary
have the cancel parameter as [in] parameter. Something
like this:

interface IWorkbookEvents : IDispatch {
....
HRESULT _stdcall BeforeSave([in] VARIANT_BOOL* Cancel);

When interop assemblies are created they are based on the
typelib and they have this parameter defined in the same
way: [in]bool& Cancel
CLR 1.1 enforces that [in] params even as pointer are not
to be marshalled back to the caller. As this was not
enforced in CLR 1.0 the cancel parameter worked with
VS.NET 2002.

RESOLUTION
===========
Steps to resolve the issue:

1. Open WordTest (the one without the PIAs) in VS.NET 2003.
2. Make sure that Cancel parameter is ignored and that
the Project is
using the interop assemblies in your project's bin
folder. Now Close the
project.
3. Open VS.NET command prompt change directory to
C:\<project
folder>\bin\Debug..
4. Run this command:
ildasm /source interop.word.dll /out=interop.word.il
--This will create interop.word.il file
5. Open this file in notepad. Replace all instance of
[in] bool& Cancel

with

[in][out] bool& Cancel

6. Save the il file
7. Run the following command:
ilasm /dll interop.word.il /out=interop.word.dll
or
ilasm /dll
interop.word.il /out=interop.word.dll /key=filename.snk
(If you want your assembly to be signed)

8. Now open the WordTest project again. Remove the
reference to word and
add reference to the new interop.word.dll manually.
9. Rebuild the project. Run the application. This should
take care of
this issue and issues with all the other Cancel
parameters.
--
Michael R
cr**@tampabay.rr.com

"AP" <ad***@indra.com> wrote in message
news:e0**************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm trying to use c# to pop up a dialog box when a user attempts to close
word to prompt them if they want to exit or cancel (obviously other stuff
needs to happen based on their selection but that's the gist of it.)
I have everything set up, and it seems to work except that setting Cancel to true and returning from my c# method appears to do nothing. Word still
closes. Am I doing something wrong?

private void wa_DocumentBeforeClose(Document Doc, ref bool Cancel) {
DialogResult dr =

MessageBox.Show("Update Template File on the Server?","Update Template
File",MessageBoxButtons.YesNoCancel,MessageBoxIcon .Question,MessageBoxDefaul tButton.Button1);
//If they cancel go back to word

if (dr == DialogResult.Cancel) {

Cancel = true;

return;

//word still closes

}

//If they say yes upload to server

if (dr == DialogResult.Yes) {

//do yes stuff

}
//NO - do nothing except

}
Adam

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
5
by: Fly Girl | last post by:
Gurus needed! I'm trying to use a Word class object in order to capture events in Word. Here's what I have, but the event code appWord_BeforeDocumentSave... doesn't ever fire. In a Class Module...
4
by: astro | last post by:
I've been looking at the event sinking example in Litwin et. al. "Access 97 Developer's Handbook" and I am able to event sink the 2 events listed - those being the "_quit" and "_documentchange"...
1
by: John | last post by:
Has anybody tried this code (http://support.microsoft.com/default.aspx?kbid=302817)?. When I run the programme it freezes when it reaches the event handler... //============ Set up the event...
2
by: Ludovic SOEUR | last post by:
Suppose I have a .Net C# Winforms App with a RichTextBox control and I want to provide an option for the user to open the Rtf in Word, edit it in Word and get the edited value back to my C# app...
5
by: John | last post by:
Hi My vb.net opens a word document from a word template. I am trying to find when the document is saved by the user so I can make a history in my vb.net app. Here is how I think it may work; ...
0
by: Vasiliy | last post by:
Hi all! I'm developing an application to manage word templates and documents. Documents are stored in database, so when user wants to edit a document i make a local copy of this document and then...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
0
by: ppardi | last post by:
I'm developing an addin for Word 2007 and I need to determine whether a user saves a Word 2007 document in an older format (97-2003) after a save as is done. The scenario is that the user starts...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.