Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8597333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:53:24+00:00 2026-06-12T00:53:24+00:00

I have an event hooked up to the DocumentBeforeClose event for a Microsoft Word

  • 0

I have an event hooked up to the DocumentBeforeClose event for a Microsoft Word document in C#.

this.Application.DocumentBeforeClose +=
                new MSWord.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);

If some logic is true, I set the Cancel flag to true, so that the document won’t close. However, although the event is fired and the Cancel flag is set to true, the document still closes.

Is this a bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:53:26+00:00Added an answer on June 12, 2026 at 12:53 am

    I finally figured it out. I needed to also hook an event handler to the actual Word Document (Microsoft.Office.Tools.Word.Document) object as well. (Tools.Word.Document and Interop.Word.Document give me headaches…)

    this.Application.DocumentBeforeClose += new Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);
    
    Application_DocumentBeforeClose(Interop.Word.Document document, ref bool Cancel)
    {
      // Documents is a list of the active Tools.Word.Document objects.
      if (this.Documents.ContainsKey(document.FullName))
      {
        // I set the tag to true to indicate I want to cancel.
        this.Document[document.FullName].Tag = true;
      }
    }
    
    public MyDocument() 
    {
      // Tools.Office.Document object
      doc.BeforeClose += new CancelEventHandler(WordDocument_BeforeClose);
    }
    
    private void WordDocument_BeforeClose(object sender, CancelEventArgs e)
    {
      Tools.Word.Document doc = sender as Tools.Word.Document;
    
      // This is where I now check the tag I set.
      bool? cancel = doc.Tag as bool?;
      if (cancel == true)
      {
        e.Cancel = true;
      }
    }
    

    So since all of my application logic is done in the Application class code, I needed a way to indicate to my MyDocument class event that I want to cancel the close event. So that’s why I use the tag object to save the flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function hooked on a $('form').submit() event. This function will fire an
I am new to Sharepoint. I have an EventReceiver hooked to an ItemUpdated event
I have two functions hooked on the submit event of a form. Each function
Our application is modulraized (Group of modules doing specific things). The modules have event
I have RowDatabound event where I want to change column names like this: Protected
I have a click event hooked up to my listview as shown. int[] GenusListIDs
I have the following: container.dialog().bind('dialogopen', function(event, ui) { ... if (someCondition) { $(this).dialog('close'); //
In my Sitecore 6.1.0 installation I have hooked onto the item:added event by implementing
I have a web application in which I have hooked mouse up and mouse
I thought that if I have this code: public event PropertyChangedEventHandler PropertyChanged; protected void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.