Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-06-2021, 06:40 AM
TheAnimal TheAnimal is offline Combining 3 VBA codes with different drop down controls Windows XP Combining 3 VBA codes with different drop down controls Office 2019
Novice
Combining 3 VBA codes with different drop down controls
 
Join Date: Sep 2021
Posts: 4
TheAnimal is on a distinguished road
Default Combining 3 VBA codes with different drop down controls

Hi,

Can anyone please tell me where I'm going wrong with this code...

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim lngIndex As Long
Dim strValue As String
Select Case CC.Title
Case "RAG"
With CC


If .ShowingPlaceholderText Then Exit Sub
Select Case .Range.Text
Case "RED": .Range.Font.Color = RGB(178, 34, 34)
Case "AMBER": .Range.Font.Color = RGB(255, 165, 0)
Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
Case Else: .Range.Font.ColorIndex = wdAuto
End Select
Select Case CC.Title
Case "Seat depth"
With CC
If .ShowingPlaceholderText Then Exit Sub
Select Case .Range.Text
Case "BLUE": .Range.Font.Color = RGB(0, 176, 240)
Case "PURPLE": .Range.Font.Color = RGB(112, 48, 160)
Case "RED": .Range.Font.Color = RGB(178, 34, 34)
Case "ORANGE": .Range.Font.Color = RGB(247, 150, 70)
Case "YELLOW": .Range.Font.Color = RGB(255, 165, 0)
Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
Case Else: .Range.Font.ColorIndex = wdAuto
End Select

For lngIndex = 2 To .DropdownListEntries.Count
If .DropdownListEntries(lngIndex).Text = .Range.Text Then
strValue = .DropdownListEntries(lngIndex).Value
.Type = wdContentControlText
.Range.Text = strValue
.Type = wdContentControlDropdownList
Exit For
End If
Next lngIndex
End With
Case Else
End Select
lbl_Exit:
Exit Sub
End Sub


The first and last parts I was kindly helped with and I'd like to add in the section in bold but I'm getting it wrong!

Thank you
Reply With Quote
  #2  
Old 11-06-2021, 05:13 PM
Guessed's Avatar
Guessed Guessed is offline Combining 3 VBA codes with different drop down controls Windows 10 Combining 3 VBA codes with different drop down controls Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,161
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

I assume you are trying to get to this
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
  Dim lngIndex As Long, strValue As String
  With CC
    If .ShowingPlaceholderText Then Exit Sub
    Select Case CC.Title
      Case "RAG"
        Select Case .Range.Text
          Case "RED": .Range.Font.Color = RGB(178, 34, 34)
          Case "AMBER": .Range.Font.Color = RGB(255, 165, 0)
          Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
          Case Else: .Range.Font.ColorIndex = wdAuto
        End Select
      Case "Seat depth"
        Select Case .Range.Text
          Case "BLUE": .Range.Font.Color = RGB(0, 176, 240)
          Case "PURPLE": .Range.Font.Color = RGB(112, 48, 160)
          Case "RED": .Range.Font.Color = RGB(178, 34, 34)
          Case "ORANGE": .Range.Font.Color = RGB(247, 150, 70)
          Case "YELLOW": .Range.Font.Color = RGB(255, 165, 0)
          Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
          Case Else: .Range.Font.ColorIndex = wdAuto
        End Select
        For lngIndex = 2 To .DropdownListEntries.Count
          If .DropdownListEntries(lngIndex).Text = .Range.Text Then
            strValue = .DropdownListEntries(lngIndex).Value
            .Type = wdContentControlText
            .Range.Text = strValue
            .Type = wdContentControlDropdownList
            Exit For
          End If
        Next lngIndex
      End Select
  End With

lbl_Exit:
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-07-2021, 03:52 AM
TheAnimal TheAnimal is offline Combining 3 VBA codes with different drop down controls Windows XP Combining 3 VBA codes with different drop down controls Office 2019
Novice
Combining 3 VBA codes with different drop down controls
 
Join Date: Sep 2021
Posts: 4
TheAnimal is on a distinguished road
Default

Andrew, Thank you so much.
I think I can see where I'm going wrong...

Below is the original code that works for the "RAG" drop down. The part in bold from the original post is for a different drop down CC "Seat depth" So I'm not sure why I just chucked it in the middle... I'll have a play around but predict I'll be back here asking again! I'm guessing I need to pop it after the DDLE value instriction but won't pretend I know what I'm doing so any help would be greatly appreciated. Thank you

Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean)
Dim lngIndex As Long
Dim strValue As String
Select Case CC.Title
Case "RAG"
With CC
If .ShowingPlaceholderText Then Exit Sub
Select Case .Range.Text
Case "RED": .Range.Font.Color = RGB(178, 34, 34)
Case "AMBER": .Range.Font.Color = RGB(255, 165, 0)
Case "GREEN": .Range.Font.Color = RGB(50, 205, 50)
Case Else: .Range.Font.ColorIndex = wdAuto
End Select
For lngIndex = 2 To .DropdownListEntries.Count
If .DropdownListEntries(lngIndex).Text = .Range.Text Then
strValue = .DropdownListEntries(lngIndex).Value
.Type = wdContentControlText
.Range.Text = strValue
.Type = wdContentControlDropdownList
Exit For
End If
Next lngIndex
End With
Case Else
End Select
lbl_Exit:
Exit Sub
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply 2 VBA codes to a single content control drop down TheAnimal Word VBA 2 09-24-2021 04:42 AM
Content Controls - Multiple Drop Downs - VBA cookietyrant Word VBA 2 08-03-2021 04:51 PM
Combining 3 VBA codes with different drop down controls Content Controls (Drop Down copy and paste), and XML mapping dezdelaina Word 3 03-05-2018 06:50 PM
Combining 3 VBA codes with different drop down controls 2 drop down list content controls danfookes Word VBA 2 03-02-2018 02:05 AM
Combining 3 VBA codes with different drop down controls Drop down options and controls in a Word form Begadoc Word 3 06-06-2016 03:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:00 AM.


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