In Word Programming, Events and Order

xiaoxiao2021-03-06  76

Open Word until open document, during this process, each happens is slightly different, we will give a common code segment for parsing: DIM WordApp As Objectdim WordDoc As Object

SET WordApp = CreateObject ("Word.Application") Wordapp.Visible = TrueSet WordDoc = Wordapp.Documents.Open ("kk.doc")

Then, the time order is as follows: 1. Application's WindowActivate event: This is better understood, first of all the Word.Application window gets focus; but not very clear is .visible = true, or createObject brought (according to us) The result of tracking should be .visible = true); 2, Application's Documentopen event: When using the code to open the document, the Documentopen event has occurred, this event occurs for Document, all if you need to do your document In this Documentopen event, it is the most appropriate; 3, Application's DocumentChange event: This event is not aimed for Document, so it is also more special, even in the window without documents, as long as you switch The Word window will happen, but his condition is: 3.1. Switch from a document to another document; 3.2. When there is no document, the window is activated (this is special, when the window with documents is re-received At the time, the event happened to be WindowActivate instead of the DocumentChange event);

Other events don't need to be prolonged. In these events, the Documentopen event occurs once, while the WindowActivate events and DocumentChange events often occur;

Supplement: When there is a document in Word.Application, switch the focus to another window. When you return to this Word document window, the DocumentChange event does not happen; but there is no document in Word.Application, each switch back To the Word window, DocumentChange event occurs;

Supplement 1: Write the ComadDins interface, through WordApp.comAddins.Item (Progid) .Object = me, you can write ADDINS to a type of external call, that is, can call the public function in Addins from the outside of the program. . However, it is necessary to pay special attention. If you want to call from JS, VC, the name of this function is best written, otherwise it will happen on the conversion.

转载请注明原文地址:https://www.9cbs.com/read-109029.html

New Post(0)