The role and order of events in Word programming

Source: Internet
Author: User
Word| programming in the process of opening Word until you open the document, the sequence of occurrences is slightly different, we give a common code snippet to parse:
Dim WordApp As Object
Dim WordDoc As Object

Set Wordapp=createobject ("Word.Application")
Wordapp.visible=true
Set Worddoc=wordapp.documents.open ("Kk.doc")

Then, the chronological order is as follows:
1, Application WindowActivate event: This better understanding, first of all Word.Application window to gain the focus; but it's not clear exactly what. Visible=true brought, or CreateObject bring it (according to the results we tracked, it should be.) Visible=true caused by);
2, Application DocumentOpen event: In the adoption of code to open the document, the corresponding occurrence of the DocumentOpen event, this incident against the document, all if you need to check the documents, In this documentopen incident, is the most appropriate;
3, Application DocumentChange event: This event does not occur for the document, so it is also more special, even in the absence of documents in the window, as long as you switch the Word window, it will occur, but his condition is:
3.1. Switch from one document to another;
3.2. When a window without a document is activated (this is particularly so, when the window that has the document gets the focus again, the event that occurs is windowactivate, not the DocumentChange event);

Other events, there is no need to wordy, in these events, the DocumentOpen event occurs once, and WindowActivate events and DocumentChange events occur frequently;

Add: The DocumentChange event does not occur when there is a document in the Word.Application, when the focus is switched to another window, and then back to the Word document window, but when there is no document in Word.Application, each switch back to the word window will Occurrence of DocumentChange events;

Supplemental 1: Written in the COMAddIns interface, via WordApp.COMAddIns.Item (ProgId). Object=me, you can write addins as a type that is called from outside, that is, you can call public functions in addins from outside the program. However, it is necessary to pay special attention to, if you want to call from the JS, VC inside, the name of this function is best to use lowercase, otherwise the conversion will be trouble.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.