Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2018, 04:58 PM
rkferguson's Avatar
rkferguson rkferguson is offline Content control font color Windows 8 Content control font color Office 2007
Novice
Content control font color
 
Join Date: Jan 2015
Posts: 5
rkferguson is on a distinguished road
Default Content control font color

I have four content controls at the end of a document that I use to display different counters. The control has default/automatic font color, the other three I assigned a font color based on their content. That is, one control is green, one is red, and the last is blue. The macro works as expected, except for the last content control. Instead of displaying in blue font, it displays as green font.

Any suggestions for what I may be doing wrong?

I have provided the macros below, I can provide the host document if necessary:

Option Explicit

'Many thanks to Mr. Greg Maxey, Greg Mayor, and Westconn1 for their help with these macros
'This macro captures user selections to questions and colors the cell according to those selections

[/CODE]Sub Document_ContentControlOnExit(ByVal oCC As ContentControl, Cancel As Boolean)

If oCC.Type = 3 Or oCC.Type = 4 Then
Select Case oCC.Range.Text
Case "Y"
oCC.Range.Cells(1).Shading.BackgroundPatternColor = &H50B000
oCC.Range.Font.ColorIndex = wdWhite
Case "N"
oCC.Range.Cells(1).Shading.BackgroundPatternColor = wdColorRed
oCC.Range.Font.ColorIndex = wdWhite
Case "NA"
oCC.Range.Cells(1).Shading.BackgroundPatternColor = &HC07000
oCC.Range.Font.ColorIndex = wdWhite
Case Else
oCC.Range.Cells(1).Shading.BackgroundPatternColor = wdColorWhite
oCC.Range.Font.Color = wdColorAutomatic
End Select
UpdateTotals
End If
lbl_Exit:


Exit Sub
End Sub

'This macro tallies the various responses to the questions in the document

Sub UpdateTotals()
Dim lngY As Long, lngN As Long, lngNA As Long, lngNullorInvalid As Long
Dim oCC As ContentControl
Dim oRng As Range

For Each oCC In ActiveDocument.Range.ContentControls
Select Case oCC.Type
Case 8
Case 3, 4
Select Case oCC.Range.Text
Case Is = "Y": lngY = lngY + 1
Case Is = "N": lngN = lngN + 1
Case Is = "NA": lngNA = lngNA + 1
Case Else: lngNullorInvalid = lngNullorInvalid + 1
End Select
End Select
DoEvents
Next oCC

ActiveDocument.SelectContentControlsByTitle("Not Selected").Item(1).Range.Text = lngNullorInvalid
ActiveDocument.SelectContentControlsByTitle("Yes") .Item(1).Range.Text = lngY
ActiveDocument.SelectContentControlsByTitle("No"). Item(1).Range.Text = lngN
ActiveDocument.SelectContentControlsByTitle("NA"). Item(1).Range.Text = lngNA

lbl_Exit:
Exit Sub
End Sub
Reply With Quote
  #2  
Old 12-18-2018, 05:06 AM
gmayor's Avatar
gmayor gmayor is offline Content control font color Windows 10 Content control font color Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The code posted does not address the font colour of the four total fields
Code:
    ActiveDocument.SelectContentControlsByTitle("Not Selected").Item(1).Range.Text = lngNullorInvalid
    ActiveDocument.SelectContentControlsByTitle("Yes").Item(1).Range.Text = lngY
    ActiveDocument.SelectContentControlsByTitle("No").  Item(1).Range.Text = lngN
    ActiveDocument.SelectContentControlsByTitle("NA").  Item(1).Range.Text = lngNA
You can modify the code to colour the fonts in those ranges e.g.
Code:
Sub UpdateTotals()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 12/2/2018
'Graham Mayor - https://www.gmayor.com - Last updated - 18 Dec 2018

Dim lngY As Long, lngN As Long, lngNA As Long, lngNullorInvalid As Long
Dim oCC As ContentControl
Dim oRng As Range
    For Each oCC In ActiveDocument.Range.ContentControls
        If oCC.Type = 3 Or oCC.Type = 4 Then
            Select Case oCC.Range.Text
                Case Is = "Y": lngY = lngY + 1
                Case Is = "N": lngN = lngN + 1
                Case Is = "NA": lngNA = lngNA + 1
                Case Else: lngNullorInvalid = lngNullorInvalid + 1
            End Select
        End If
        DoEvents
    Next oCC

    Set oRng = ActiveDocument.SelectContentControlsByTitle("Not Selected").Item(1).Range
    oRng.Text = lngNullorInvalid
    oRng.Font.ColorIndex = wdRed
    Set oRng = ActiveDocument.SelectContentControlsByTitle("Yes").Item(1).Range
    oRng.Text = lngY
    oRng.Font.ColorIndex = wdGreen
    Set oRng = ActiveDocument.SelectContentControlsByTitle("No").Item(1).Range
    oRng.Text = lngN
    oRng.Font.ColorIndex = wdBlue
    Set oRng = ActiveDocument.SelectContentControlsByTitle("NA").Item(1).Range
    oRng.Text = lngNA
    oRng.Font.ColorIndex = wdDarkYellow


lbl_Exit:
    Set oRng = Nothing
    Set oCC = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
word; content controls



Similar Threads
Thread Thread Starter Forum Replies Last Post
Content control font color Changing color of instructional text in a content control box Document Specialist Word 2 08-17-2018 05:25 AM
Table with content control drop down - change font DebA Word 3 04-29-2018 09:07 PM
Content control font color Text Field [content control] - Default text color vs Filled Text color jackcoletti Word 3 02-01-2017 08:10 AM
Content control font color Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM
Content control font color text appears in prompt font in RTF content control eli.rhodes Word 1 09-18-2013 08:32 AM

Other Forums: Access Forums

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


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