开发者

Change font size in form combo box in MS Excel

I need to change the font size in an Excel combo box because the default font size is way too small. Is there a way to do this?

Change font size in form combo box in MS Excel

This is the code I use for my macro:

Option Explicit

Sub DropDown4_Change()
    Dim comboValue As String
    Dim Key1ColumnIndex As Integer
    Dim Key2ColumnIndex As Integer
    Dim Index As Integer
    Dim comboName As String
    Dim comboName2 As String
    Dim comboID As Integer

    'You can get the name 开发者_JS百科by doing something like this in the immediate window:  "? Sheet1.Shapes(1).OLEFormat.Object.Name"

     For Index = 1 To ActiveSheet.Shapes.Count
        comboName = ActiveSheet.Shapes(Index).OLEFormat.Object.Name
        If InStr(comboName, "Drop") > 0 Then
            'MsgBox InStr(comboName, "Drop")
            comboName2 = comboName
            comboID = Index
        End If
     Next


    comboValue = ActiveSheet.Shapes(comboID).ControlFormat.List(ActiveSheet.Shapes(comboID).ControlFormat.ListIndex)

    Select Case comboValue

        Case "By Keyphrase"
            Key1ColumnIndex = 18
            Key2ColumnIndex = 19
        Case "By Region"
            Key1ColumnIndex = 19
            Key2ColumnIndex = 18
        Case "Default"
            Key1ColumnIndex = 1
            Key2ColumnIndex = 1
    End Select


   Range("DataValues").sort Key1:=Range("DataValues").Cells(1, Key1ColumnIndex), _
                            Order1:=xlAscending, Header:=xlNo, DataOption1:=xlSortNormal, _
                            Key2:=Range("DataValues").Cells(1, Key2ColumnIndex), order2:=xlAscending
End Sub

Thank you.


It can't be done

There's no formatting the font size of a forms dropdown - even programatically. If it's an absolute requirement, you'll have to switch this to an activeX control.


As said by @Alain you simply can't in a clean way, or you have to use an activeX control.

But here there's also a workaround. With programming, you can temporarily zoom the worksheet, to make the data validation font size appear larger.

Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
  If Target.Address  = "$A$2" Then 
    ActiveWindow.Zoom = 120 
  Else 
    ActiveWindow.Zoom = 100 
  End If 
End Sub 

Credits and more details: https://www.contextures.com/xldataval08.html#zoommacro

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜