Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2014, 03:29 PM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default Conditional Formatting on Word (Dropdown List)

Good evening,



I am trying to create/find a macro for MS Word VBA to adjust the font colour of the various lists (I believe there are 14 small lists in the document) based on what is selected.

For the 14 items, the default value includes one of the following (if they have not chosen one of the other options in the list):

Choose an Item
If "Yes", Select
Select Date
n/a

What I want to do is to make those values in the font colour red. Any other option they choose in the various lists should show up as black, to show that they have filled in the field.

A macro to do all of this would be greatly appreciated. Do let me know if you need any other information.
Reply With Quote
  #2  
Old 12-05-2014, 04:20 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

What kind of dropdown list (content control, formfield, ActiveX) and what do you want to colour - the dropdown item's colour or something else?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-05-2014, 04:56 PM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

Good evening Paul,

Thanks for the response.

The list was created with content control.

I want to colour the font of the text. So for the four instances I listed, those I would ideally want in red. For everything else I want it in black. Aesthetically, the red looks perfect on what I am doing. But having it stay red almost looks like it is incomplete, so having the colour change to black once the user selects one of the other dropdown menu options is a definite advantage.

Let me know if you need to know anything else,


Dave
Reply With Quote
  #4  
Old 12-05-2014, 05:19 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

In that case, you could add a 'ContentControlOnExit' macro to your document's 'ThisDocument' code module, coded along the lines of:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
With CCtrl
  Select Case .Title
    Case "Dropdown1", "Dropdown2"
        Select Case .Range.Text
          Case .PlaceholderText, "If ""Yes"", Select", "n/a"
            .Range.Font.ColorIndex = wdRed
          Case Else
          .Range.Font.ColorIndex = wdAuto
        End Select
  End Select
End With
End Sub
where "Dropdown1", "Dropdown2", etc. are the titles you assign to your content controls and .PlaceholderText, "If ""Yes"", Select", "n/a", etc. are the default text and any other options you want to assign the red colour to.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-05-2014, 06:09 PM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

Hi Paul,

Two things for you:

1) When I add "Select Date" or another one of the headers, I get an error message. Not sure why.

2) All of the dropdown lists turn into red font, as opposed to just those options. Would you know why?

Thanks!
Reply With Quote
  #6  
Old 12-05-2014, 10:20 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Without seeing your document, or more detail on what you've done, I can't say why you'd get those results.

The attached document has two rows of content controls - dropdown, date & text. Each displays in red while the default text is displayed, the dropdown also does so if 'N/A' is selected; otherwise they display normally.
Attached Files
File Type: docm CCtrlColours.docm (39.3 KB, 50 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-06-2014, 07:57 AM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

It's working a lot better now! Almost everything works.

One last problem: I have the same list name for the two date fields as the other fields (titled "Select"), with the default selection saying "Select Date". I want that to be red until the user selects a date, and then it will go black. But I get Run-time Error 91: "Object variable or With block variable not set."

What do you think I need to change, especially because everything else works.
Reply With Quote
  #8  
Old 12-06-2014, 01:16 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

As I said before:
Quote:
Without seeing your document, or more detail on what you've done, I can't say why you'd get those results.
Can you attach a document to a post with some representative content (delete anything sensitive), including your code? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 12-06-2014, 02:48 PM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

Sorry, keeps timing out when I try to attach. See attached now.

I took the code out of this so you can just try it from scratch. If the code you put in works, I'll just copy and paste it into the other one and see if it works.

Really appreciate it!
Attached Files
File Type: docx Test.docx (27.4 KB, 15 views)
Reply With Quote
  #10  
Old 12-06-2014, 10:43 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

It's not much good posting the document without the code, as that's what's generating the error messages.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-07-2014, 12:47 AM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

No problem. Here you are.
Attached Files
File Type: docm Test.docm (33.3 KB, 17 views)
Reply With Quote
  #12  
Old 12-07-2014, 03:46 AM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The problem was that you'd deleted the placeholder text for the two date controls. The following macro will fix that:
Code:
Sub FixDateCtrls()
With ActiveDocument.SelectContentControlsByTitle("Select Date")
  .Item(1).SetPlaceholderText Text:="Select Date"
  .Item(2).SetPlaceholderText Text:="Select Date"
End With
End Sub
With the ContentControlOnExit macro itself, it seems you haven't really understood how it works. You really don't need to include all of "Dropdown1", "Date1", "Text1", "Select", "Select Date" for the Title selection when you're only concerned with "Select" & "Select Date". Furthermore, when testing the content control's display, you don't need to test all of .PlaceholderText, "n/a", "Choose an Item", "If Yes, Select", "Select Date", when "Choose an Item" & "Select Date" (after running the above macro) are themselves the Placeholder text.

Try the following:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
With CCtrl
  Select Case .Title
    Case "Select"
      Select Case .Range.Text
        Case .PlaceholderText, "n/a", "If Yes, Select"
          .Range.Font.ColorIndex = wdRed
        Case Else
        .Range.Font.ColorIndex = wdAuto
      End Select
    Case "Select Date"
      Select Case .Range.Text
        Case .PlaceholderText
          .Range.Font.ColorIndex = wdRed
        Case Else
        .Range.Font.ColorIndex = wdAuto
      End Select
      With .Range.Font
        .Size = 8
        .Italic = True
      End With
    Case Else
  End Select
End With
Application.ScreenUpdating = True
End Sub
Note how I have separate processes for the 'Select' & 'Select Date' controls. That basically comes down to the latter using italics and to coerce it to remain at 8pt when displaying the Placeholder text - which wouldn't be necessary if you used a Style with those attributes.

You might also want to set each content control's 'cannot be deleted' property, to guard against errant users.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 12-07-2014, 07:36 AM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

Hey Paul,

Yeah I left those title selections in there and just included the ones I needed to the right.

Anytime I run it now, I get an error when selecting a date (same run-time error as before) and it highlights the "Case .PlaceholderText".
Reply With Quote
  #14  
Old 12-07-2014, 01:16 PM
macropod's Avatar
macropod macropod is online now Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Did you run the FixDateCtrls macro first?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 12-07-2014, 01:33 PM
daviieejay daviieejay is offline Conditional Formatting on Word (Dropdown List) Windows 7 64bit Conditional Formatting on Word (Dropdown List) Office 2010 64bit
Novice
Conditional Formatting on Word (Dropdown List)
 
Join Date: Dec 2014
Posts: 12
daviieejay is on a distinguished road
Default

Sorry had to close it and now it works.

Does that mean that the macro will have to be run before each time it is used?
Reply With Quote
Reply

Tags
color, conditional formatting, list



Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Formatting on Word (Dropdown List) Conditionally Color Formatting Text selected from a dropdown list in Word 2010 pgammag Word 9 08-20-2019 04:17 PM
Dropdown conditional formatting tlkc67 Word VBA 6 10-05-2014 10:54 AM
Conditional Formatting on Word (Dropdown List) Conditional formatting that ignores other formatting rules info_guy2 Excel 1 07-03-2014 10:07 AM
Dropdown List in Microsoft Word 2010 bfarquhar Word 2 04-02-2014 07:48 PM
Conditional Formatting on Word (Dropdown List) link conditional info in word based on excel list stijnvanhoof Mail Merge 1 11-13-2012 01:55 PM

Other Forums: Access Forums

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