Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-26-2023, 04:23 PM
Journeyman Journeyman is offline How to find the content control ID after selection Windows 10 How to find the content control ID after selection Office 2019
Novice
How to find the content control ID after selection
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default 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)
Surely you'd think more could be provided by the information than just a Boolean value.

This will return Text within a specific (or known) control
Code:
ActiveDocument.ContentControls(strControlName).range.text
Where strControlName is the known title or ID of the control.... except I don't know it until it's selected.

This apparently returns the ID of the selected control - if it is in design mode
Code:
Selection.range.ContentControl(1).ID
Although I've never been able to make that work in any way... doesn't exist error.

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
All of this is fabulous and wonderful... except not a single method provides for the selection of the control itself.

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
Reply With Quote
  #2  
Old 07-26-2023, 09:25 PM
Guessed's Avatar
Guessed Guessed is offline How to find the content control ID after selection Windows 10 How to find the content control ID after selection Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can change the selection to the full CC by using
Code:
Selection.Range.ParentContentControl.Range.Select
If you want the actual CC instead of the text in it you could use
Code:
  Dim aCC As ContentControl
  Set aCC = Selection.Range.ParentContentControl
  aCC.Title = "Found It"
Disclaimer: I didn't know the answer either so I had to search for this and found the relevant clue on this post by user11818836 on c# - How to set ContentControl.Range to the current ContentControl I am working from? - Stack Overflow
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-27-2023, 01:39 AM
Italophile Italophile is online now How to find the content control ID after selection Windows 11 How to find the content control ID after selection Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Journeyman View Post
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
This is rather confusing.

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.
Reply With Quote
  #4  
Old 07-27-2023, 02:35 AM
Journeyman Journeyman is offline How to find the content control ID after selection Windows 10 How to find the content control ID after selection Office 2019
Novice
How to find the content control ID after selection
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default

Quote:
Originally Posted by Italophile View Post
They are, and always have been, document level events and can be accessed via the ThisDocument module.
Thanks for your response.

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
Reply With Quote
  #5  
Old 07-27-2023, 03:22 AM
Italophile Italophile is online now How to find the content control ID after selection Windows 11 How to find the content control ID after selection Office 2021
Expert
 
Join Date: Mar 2022
Posts: 338
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by Journeyman View Post
In any case, the question remains: How do I access any one of the number of ActiveX Textboxes and their change/update events.
As with Content Controls the event handlers for ActiveX controls are found in the ThisDocument module.
Attached Images
File Type: png Screenshot 2023-07-27 111810.png (62.7 KB, 7 views)
Reply With Quote
  #6  
Old 07-27-2023, 02:06 PM
Journeyman Journeyman is offline How to find the content control ID after selection Windows 10 How to find the content control ID after selection Office 2019
Novice
How to find the content control ID after selection
 
Join Date: Feb 2023
Posts: 15
Journeyman is on a distinguished road
Default

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).
It functions similarly an AfterUpdate event, and allow me to trap the content change. This is precisely what I was after.

Anyway, thanks for tips.
Reply With Quote
Reply



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
How to find the content control ID after selection Edit table cells based on content control selection gennatr12 Word VBA 7 03-26-2017 08:51 PM
How to find the content control ID after selection 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft