Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2018, 12:48 AM
MP1989 MP1989 is offline VBA to provide text string with specific formating based on Drop down list (content control) Windows 10 VBA to provide text string with specific formating based on Drop down list (content control) Office 2010 64bit
Novice
VBA to provide text string with specific formating based on Drop down list (content control)
 
Join Date: Jun 2018
Posts: 9
MP1989 is on a distinguished road
Default VBA to provide text string with specific formating based on Drop down list (content control)

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
Reply With Quote
  #2  
Old 07-30-2018, 01:24 AM
macropod's Avatar
macropod macropod is offline VBA to provide text string with specific formating based on Drop down list (content control) Windows 7 64bit VBA to provide text string with specific formating based on Drop down list (content control) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Where is this output to appear - in the dropdown content control itself, or somewhere else?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-30-2018, 01:28 AM
MP1989 MP1989 is offline VBA to provide text string with specific formating based on Drop down list (content control) Windows 10 VBA to provide text string with specific formating based on Drop down list (content control) Office 2010 64bit
Novice
VBA to provide text string with specific formating based on Drop down list (content control)
 
Join Date: Jun 2018
Posts: 9
MP1989 is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-30-2018, 01:45 AM
gmayor's Avatar
gmayor gmayor is offline VBA to provide text string with specific formating based on Drop down list (content control) Windows 10 VBA to provide text string with specific formating based on Drop down list (content control) Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

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
Reply With Quote
  #5  
Old 07-30-2018, 02:40 AM
macropod's Avatar
macropod macropod is offline VBA to provide text string with specific formating based on Drop down list (content control) Windows 7 64bit VBA to provide text string with specific formating based on Drop down list (content control) Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 gmayor View Post
Youi cannot format a content control dropdown list in this manner.
Au contraire, assuming the content control is given the tag 'Dropdown' :
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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to provide text string with specific formating based on Drop down list (content control) Insert Rich Text Content Control in specific position, Word 2013 VBA LaurenM Word VBA 13 12-01-2017 02:07 AM
VBA to provide text string with specific formating based on Drop down list (content control) Export Word Drop-Down Content Control to Excel Specific Sheet nolanthomas32 Word VBA 4 09-19-2017 06:25 AM
VBA to provide text string with specific formating based on Drop down list (content control) How to get a Drop Down List Content Control box to fill in other areas snips1982 Word 2 03-22-2017 03:37 AM
VBA to provide text string with specific formating based on Drop down list (content control) 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

Other Forums: Access Forums

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