![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Hi all,
I am trying to create a drop down list (content control) and then based on the selection (high, significant or Low) produce text but with some formatting; 'High' = High / Significant / Low (High in bold, significant / Low with strikethrough) 'Significant = High / Significant / Low (Significant in bold, High / Low with strikethrough) 'Low' = High / Significant / Low (Low in bold, High / Significant with strikethrough) I don't seem to be able to do this in the content control box, but I may be doing something wrong so though about VBA? I don't appear to be able to apply formatting simply (copy and paste) and don't know the right words to define the formatting I require and in the layout required, if this is possible. Anyone able to help? Thanks |
|
#2
|
||||
|
||||
|
Where is this output to appear - in the dropdown content control itself, or somewhere else?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Hi Paul,
I have set up a table, I want to select high ... from the drop down and then it to display the required output in the same cell, instead of the text. Open to suggestions if I am going about this the wrong way. |
|
#4
|
||||
|
||||
|
Youi cannot format a content control dropdown list in this manner.
You could use a selection to format text in the document, or perhaps simpler use it to insert an appropriate formatted autotext entry in a bookmarked location e.g. Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim orng As Range
Select Case ContentControl.Range.Text
Case "High"
AutoTextToBM "bmRating", ActiveDocument.AttachedTemplate, "High"
Case "Significant"
AutoTextToBM "bmRating", ActiveDocument.AttachedTemplate, "Significant"
Case "Low"
AutoTextToBM "bmRating", ActiveDocument.AttachedTemplate, "Low"
Case Else
Set orng = ActiveDocument.Bookmarks("bmRating").Range
orng.Text = ""
ActiveDocument.Bookmarks.Add ("bmRating"), orng
End Select
lbl_Exit:
Set orng = Nothing
Exit Sub
End Sub
Private Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String)
'strBMName is the name of the bookmark to fill
'oTemplate is the template with the autotext - probably ActiveDocument.AttachedTemplate
'strAutotext is the name of the autotext entry
Dim orng As Range
On Error GoTo lbl_Exit
With ActiveDocument
Set orng = .Bookmarks(strbmName).Range
Set orng = oTemplate.AutoTextEntries(strAutotext).Insert _
(Where:=orng, RichText:=True)
.Bookmarks.Add Name:=strbmName, Range:=orng
End With
lbl_Exit:
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 |
|
#5
|
||||
|
||||
|
Quote:
:Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim strTxt As String, Rng As Range
With CCtrl
If .Tag <> "Dropdown" Then Exit Sub
If .ShowingPlaceholderText = True Then
.Range.Font.StrikeThrough = False
.Range.Font.Bold = False
Exit Sub
End If
strTxt = .Range.Text
If InStr(strTxt, "\") > 0 Then Exit Sub
.Type = wdContentControlRichText
.Range.Font.StrikeThrough = False
.Range.Font.Bold = False
With .Range
.Text = "High\Significant\Low"
.Font.StrikeThrough = True
Set Rng = .Duplicate
With Rng
.End = .Start + InStr(.Text, "\")
.Start = .End - 1
.Font.StrikeThrough = False
End With
Set Rng = .Duplicate
With Rng
.End = .Start + InStrRev(.Text, "\")
.Start = .End - 1
.Font.StrikeThrough = False
End With
Set Rng = .Duplicate
With Rng
.Start = .Start + InStr(.Text, strTxt) - 1
If InStr(.Text, "\") > 1 Then .End = .Start + InStr(.Text, "\") - 1
.Font.StrikeThrough = False
.Font.Bold = True
End With
End With
.Type = wdContentControlDropdownList
End With
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 07-30-2018 at 03:20 AM. Reason: Updated code |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Insert Rich Text Content Control in specific position, Word 2013 VBA
|
LaurenM | Word VBA | 13 | 12-01-2017 02:07 AM |
Export Word Drop-Down Content Control to Excel Specific Sheet
|
nolanthomas32 | Word VBA | 4 | 09-19-2017 06:25 AM |
How to get a Drop Down List Content Control box to fill in other areas
|
snips1982 | Word | 2 | 03-22-2017 03:37 AM |
How do I add selection of multi line content control list to specific table cell
|
Dudlee | Word VBA | 1 | 09-20-2016 04:58 PM |
| Word 2010 Content Control help - Combo Boxes vs Drop Down List | proghy | Word | 1 | 09-16-2014 02:01 PM |