Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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,142
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 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
 



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 01:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft