Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2025, 10:19 AM
CompletelyLost CompletelyLost is offline How to auto populate a rich text content control box from a selection in a combo control box Windows 11 How to auto populate a rich text content control box from a selection in a combo control box Office 2021
Novice
How to auto populate a rich text content control box from a selection in a combo control box
 
Join Date: Apr 2025
Posts: 4
CompletelyLost is on a distinguished road
Default

Thanks Greg. Here's my problem. I already have a macro with Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean), so when I try to start another one, it tells me it's already in use. I've tried merging them together and that didn't work. It just messed up the first one. Did I mention I'm not a programmer and have no idea what I'm doing LOL. This is said current macro using the ContentControlOnExit:

Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim oDLE As ContentControlListEntry
With CCtrl
If .Type = wdContentControlComboBox Then
For Each oDLE In .DropdownListEntries
If oDLE.Text = .Range.Text Then
.Range.Text = oDLE.Value
Exit For
End If
Next
End If
End With
End Sub

That said, I was trying to avoid having to spell out exactly the contractor name that is selected in the drop down as there is no difference in Display Name and Value as you show by using the Case function. The above macro is being used to select the Value instead of the Display name in dropdowns that are different. I just want if Company A is selected from the Contractor dropdown, I want my Company text box to show Company A. Can I add what I want to the above macro somehow? If this is not possible, I will have to type out all of the companies as you have suggested by using the Case function, but how do I merge it with the above so I don't get an error?



This will be an internal document only. It's basically a contract that I'm trying to make idiot proof LOL.
Reply With Quote
  #2  
Old 04-23-2025, 10:44 AM
gmaxey gmaxey is offline How to auto populate a rich text content control box from a selection in a combo control box Windows 10 How to auto populate a rich text content control box from a selection in a combo control box Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,635
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

If you have two or more CCs you want to handle with a Change Event, then use something like this:

Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim oDLE As ContentControlListEntry
  With CCtrl
    Select Case .Title
    Case "Demo1"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
    Case "Contractor"
      For Each oDLE In .DropdownListEntries
        If oDLE.Text = .Range.Text Then
          .Range.Text = oDLE.Value
          ActiveDocument.SelectContentControlsByTitle("Company").Item(1).Range.Text = oDLE.Value
          Exit For
        End If
      Next oDLE
    End Select
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to auto populate a rich text content control box from a selection in a combo control box Auto populate a text field based on Content Control Dropdown List matthias92701 Word VBA 2 05-02-2019 03:54 PM
Copy Formatted Text in one Rich Text Content Control to another Rich Text Content Control Haygordon Word 1 04-05-2019 05:43 AM
How to auto populate a rich text content control box from a selection in a combo control box Auto populate text box based on drop-down content control and repeat the process via copy paste helenndp Word VBA 2 09-27-2018 11:04 AM
Combo Box Content Control Calculate on selection help ciresuark Word 0 03-06-2015 01:49 PM
How to auto populate a rich text content control box from a selection in a combo control box How do you set rich text in a content control Testor Word VBA 4 07-08-2012 07:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:12 PM.


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