Add colored font to context menu

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hello all,

Is there any way to make the font bold or red in a context menu?

Code:
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=6)        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_EVENT"
        .FaceId = 353
        .Caption = "BUSINESS/WORK EVENT"
    End With
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

Dim ContextMenu As CommandBar
Dim ctrl As CommandBarControl


Application.CommandBars("Cell").Reset


If Intersect(Target, Range("E89:R106,E108:R125,E127:R144,E146:R163,E194:R207,E165:R167,E169:R169,E171:R171,E173:R173,E175:R175,E177:R177,E179:R179,E181:R181,E183:R183,E185:R185,E187:R187,E189:R189,E191:R191")) Is Nothing Then
    Application.CommandBars("Cell").Reset
    Exit Sub
Else


    Set ContextMenu = Application.CommandBars("Cell")


    For Each ctrl In ContextMenu.Controls
            ctrl.Delete
    Next ctrl
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=1)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO"
        .FaceId = 2113
        .Caption = Sheets("Settings").Range("K16") & " " & Sheets("Settings").Range("L16")
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=2)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_OTHER"
        .FaceId = 1845
        .Caption = Sheets("Settings").Range("K17") & " " & Sheets("Settings").Range("L17")
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=3)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_NOTE"
        .FaceId = 916
        .Caption = "CUSTOM NOTES"
        '.Font.Color = vbWhite
        '.Interior.Color = vbBlack
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=4)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_JURY"
        .FaceId = 2131
        .Caption = Sheets("Settings").Range("K18") & " " & Sheets("Settings").Range("L18")
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=5)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_MATERNITY"
        .FaceId = 2777
        .Caption = Sheets("Settings").Range("K19") & " " & Sheets("Settings").Range("L19")
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=6)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_EVENT"
        .FaceId = 353
        .Caption = Sheets("Settings").Range("K20") & " " & Sheets("Settings").Range("L20")
    End With


    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=7)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO_CUSTOM"
        .FaceId = 484
        .Caption = Sheets("Settings").Range("K21") & " " & Sheets("Settings").Range("L21")
    End With
    
    With ContextMenu.Controls.Add(Type:=msoControlButton, before:=8)
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "CLEAR"
        .FaceId = 2087
        .Caption = "*!CLEAR REQUESTS!*"
    End With
End If


End Sub
 
Upvote 0
Hello all,

Is there any way to make the font bold or red in a context menu?

Hi Andrew,

AFAIK, no. These simply are not available properties of the created control. If you Set a reference specifically to the created CommandBarButton, you will get intellisense showing the available 'stuff'

<font face=Courier New><SPAN style="color:#00007F">Dim</SPAN> cbtn <SPAN style="color:#00007F">As</SPAN> CommandBarButton<br></FONT>

<font face=Courier New>****<SPAN style="color:#00007F">Set</SPAN> cbtn = ContextMenu.Controls.Add(Type:=msoControlButton, before:=1)<br>****<SPAN style="color:#00007F">With</SPAN> cbtn<br>********<SPAN style="color:#007F00">'.OnAction = "'" & ThisWorkbook.Name & "'!" & "RTO"</SPAN><br>********.FaceId = 2113<br>********.Caption = Sheets("Settings").Range("K16") & " " & Sheets("Settings").Range("L16")<br>********<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>****</FONT>
Hope that helps,

Mark
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,427
Messages
6,124,831
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top