Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2021, 01:59 PM
GoChatter GoChatter is offline How to change VB code so dropdown conditional format color changes to "wdLightOrange" Windows XP How to change VB code so dropdown conditional format color changes to "wdLightOrange" Office 2016
Novice
How to change VB code so dropdown conditional format color changes to "wdLightOrange"
 
Join Date: Apr 2021
Posts: 2
GoChatter is on a distinguished road
Question How to change VB code so dropdown conditional format color changes to "wdLightOrange"

I am trying to figure out how to insert a dropdown list (Choose Item: High, Medium, low) into a report table in MS Word. I need High to = wdRed, Medium to = wdLightOrange (Hex: #FF9900), and Low to = wdYellow. I found the following code:


in a file named "Content Controls - Dropdown Conditional Format.docm" that I found from the 'macropd' Administrator, Paul Edstein URL: https://www.msofficeforums.com/word-...html#post47254

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
  If Len(.Title) < 4 Then Exit Sub
  If Left(.Title, 4) = "Risk" Then
    Select Case .Range.Text
      Case "High": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdRed
      Case "Medium": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
      Case "Low": .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdBrightGreen
      Case Else: .Range.Cells(1).Shading.BackgroundPatternColorIndex = wdNoHighlight
    End Select
  End If
End With
End Sub
In Paul's document, I successfully changed the Low from "wdBrighGreen" to "wdYellow" but when I try to replace the Medium from "wdYellow" to "wdLightOrange", it breaks the code. The following text is highlighted in bright yellow with an arrow next to it): "Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)"

What do I need to do to get my table to highlight with Light orange (HEX: #FF9900) when I select the Medium from the form field drop down box?

Am attaching the one I downloaded from Paul Edstein and the one I am working on.

Last edited by macropod; 04-20-2021 at 02:27 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 04-20-2021, 02:30 PM
macropod's Avatar
macropod macropod is offline How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Windows 10 How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Use:
.BackgroundPatternColor = wdColorLightOrange
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-20-2021, 05:32 PM
GoChatter GoChatter is offline How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Windows XP How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Office 2016
Novice
How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot;
 
Join Date: Apr 2021
Posts: 2
GoChatter is on a distinguished road
Default

Thank you Paul! Really wish I had some programming knowledge. I have another question... Where should I paste the code? When I look at your document, I only see it in the VBA area; not the Macro area. However when I copy the code and paste it into my word document, nothing happens when I select something from the drop down menu.

I've attached images.
Attached Images
File Type: png Paul-VisualBasicCode.PNG (71.4 KB, 15 views)
File Type: png Paul-MacrosImage.PNG (43.2 KB, 15 views)
File Type: png HC-VisualBasicCode.PNG (76.5 KB, 15 views)
Reply With Quote
  #4  
Old 04-20-2021, 05:46 PM
macropod's Avatar
macropod macropod is offline How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Windows 10 How to change VB code so dropdown conditional format color changes to &quot;wdLightOrange&quot; Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by GoChatter View Post
Thank you Paul! Really wish I had some programming knowledge. I have another question... Where should I paste the code? When I look at your document, I only see it in the VBA area; not the Macro area. However when I copy the code and paste it into my word document, nothing happens when I select something from the drop down menu.
The code goes in the 'ThisDocument' code module of the document (as is the code in the 'demo' document I posted) or, if you're using a particular template and want to have all the document based on that template have access to the same code, in the 'ThisDocument' code module of that template. The latter would also allow your documents to be saved in the docx format.

Macros that take arguments (in this case ByVal ContentControl As ContentControl, and Cancel As Boolean) are not accessible via the GUI.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting date change "Y" lolla70 Excel Programming 3 04-24-2019 11:13 AM
Need help with conditional formatting & returning "Pass" / "Fail Results" in a Column N mikey386 Excel 2 12-11-2014 01:14 PM
Change "File As" and "Display As" format davesp Outlook 0 10-14-2014 12:10 PM
Is there a way to change "Genesis" Theme Color from Blue to Green FUNKSTICK PowerPoint 13 03-12-2014 12:29 AM
How to globally change default "pattern fill" color for all shapes in PP 2013 tbach PowerPoint 1 01-31-2014 10:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:27 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