vba 在 MS Excel 中的表单组合框中更改字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7636115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:10:14  来源:igfitidea点击:

Change font size in form combo box in MS Excel

excelvba

提问by Jorge

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?

我需要更改 Excel 组合框中的字体大小,因为默认字体大小太小了。有没有办法做到这一点?

Combo in MS Excel sheet

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 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.

谢谢你。

回答by Alain

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.

没有格式化表单下拉列表的字体大小 - 即使以编程方式。如果这是绝对要求,则必须将其切换到 activeX 控件。