|
#1
|
|||
|
|||
How to find the content control ID after selection
Hi All,
I have a word document with several ActiveX Textbox controls laid out in a form. I need an event to run on the selection of those controls - specific to the selected control. For some very odd reason Microsoft chose to remove the events for ActiveX controls, so now I'm left trying to code events to trap a change. This will return true if my selection is within an ActiveX Content Control Code:
Selection.Infomation(wdInformation.wdInContentControl) This will return Text within a specific (or known) control Code:
ActiveDocument.ContentControls(strControlName).range.text This apparently returns the ID of the selected control - if it is in design mode Code:
Selection.range.ContentControl(1).ID And I can loop through all control on the document to return all control information. Code:
For i = 1 to ActiveDocument.ContentControls(i).count Debug.Print ActiveDocument.ContentControls(i).ID Next i What is the secret to returning the selected control - and it's corresponding text or information? Alternatively - and this would be magic sauce - an AfterUpdate event of some kind for the control (doesn't exist in word, i know, but... magic. All help appreciated. Cheers |
#2
|
||||
|
||||
You can change the selection to the full CC by using
Code:
Selection.Range.ParentContentControl.Range.Select Code:
Dim aCC As ContentControl Set aCC = Selection.Range.ParentContentControl aCC.Title = "Found It"
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Quote:
You first say that you have ActiveX Textboxes, then the rest of your post is about content controls. The two are entirely different. Content controls have nothing to do with ActiveX. The events for content controls have not been removed. They are, and always have been, document level events and can be accessed via the ThisDocument module. |
#4
|
|||
|
|||
Quote:
Okay, so I am working with ActiveX text boxes, which happen to be located in roughly the same place on the developer tab as legacy content controls - which have a code selection. I apologise this was not clear. In any case, the question remains: How do I access any one of the number of ActiveX Textboxes and their change/update events. The purpose is that I want to trigger the applicable code to the applicable ActiveX control set into a word document (User Form) - an example would be gratefully appreciated. Many thank |
#5
|
|||
|
|||
As with Content Controls the event handlers for ActiveX controls are found in the ThisDocument module.
|
#6
|
|||
|
|||
So I found the solution.
Thee is an event in the Standard Rich Text control that allows for the update: Code:
Document_ContentControlOnExit(ByVal ContentControl, Cancel as Boolean). Anyway, thanks for tips. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
font color based on content control pulldown selection | PbFoot | Word VBA | 3 | 01-03-2023 08:22 AM |
Lock or unlock a content control depending on the selection from the drop down list | ncruz | Word VBA | 4 | 10-15-2021 08:50 AM |
Edit table cells based on content control selection | gennatr12 | Word VBA | 7 | 03-26-2017 08:51 PM |
How do I add selection of multi line content control list to specific table cell | Dudlee | Word VBA | 1 | 09-20-2016 04:58 PM |
Combo Box Content Control Calculate on selection help | ciresuark | Word | 0 | 03-06-2015 01:49 PM |