The demonstration above should show that it can serve the dual purposes of the "Calculate on exit" or "Run a macro on exit" function available in legacy form fields. Note: The Document_ContentControlOnExit event is a new document event introduced with content controls in Word 2007. 'The user exited some other content control that we don't care about. MsgBox "The user selected an offense, specifically: " & MsgBox "The user selected a file, specifically: " & Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, _ The VBE should be configured as shown below:.Using the dropdown at top right of the code pane, select ContentConrtrolOnExit. Using the dropdown at top left of the code pane, select the "Document" object.Using the Project Explorer, drill down and select the project "Template Project (Demo), expand the project and double-click the "ThisDocument" module. Note: A template isn't necessary for this review, but we will be using features of a template as the examples are developed so we might as well start with one now. For the purpose of the illustrations that follow I saved the document to my desktop using the name "Demo.dotm" Save the new document as a Word macro-enabled template.The following steps provide a working example and review of the event. Understanding this event is key to examples that follow. This is a built-in document event that you can leverage each time your document user exits a document content control range. OnExit Event:īefore getting to the examples I want to ensure that all visitors to this page are familiar with the Document_ContentControlOnExit event. Most of the examples could easily be adapted to include the insertion of data from other external sources (e.g., Excel or Access). Note: I have limited the discussion and examples in this page to Microsoft Word. It can also include text strings included in VBA procedures or even document variables.įriend and frequent tips project collaborator Graham Mayor provides a similar discussion and examples for inserting content based on a user selection or entry in legacy form fields: Insert content from a form fieldįor more on Content Controls see: Content Controls The source of the defined content can include text and graphics stored in other Word documents or text and graphics stored as Building Blocks in the document template or other external template (e.g., the Word Built-In Building Blocks.dotx). The purpose of this Microsoft Word Tips & Microsoft Word Help page is to review/introduce readers to the Document_ContentControlOnExit event and illustrate several methods that you can use to insert defined content (text or graphics) into your Word documents based on a selection or entry the document user makes in the document content controls
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |