Excel ActiveX控件受PC分辨率的影响

bjg7j2ky  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(108)

我刚被指派维护Excel VBA脚本,我在工作表上创建了一个UI,但是我发现PC的分辨率会影响Excel文档的UI,比如用户点击时会导致按钮大小变大,按钮文本大小变小,有人知道怎么解决吗?

oyt4ldly

oyt4ldly1#

我试过这个解决方案,它是完全可行的。
参考来源:VBA Excel Button resizes after clicking on it (Command Button)
子共享对象重置()

Dim MyShapes As OLEObjects
Dim ObjectSelected As OLEObject

Dim ObjectSelected_Height As Double
Dim ObjectSelected_Top As Double
Dim ObjectSelected_Left As Double
Dim ObjectSelected_Width As Double
Dim ObjectSelected_FontSize As Single

ActiveWindow.Zoom = 100

'OLE Programmatic Identifiers for Commandbuttons = Forms.CommandButton.1
Set MyShapes = ActiveSheet.OLEObjects
For Each ObjectSelected In MyShapes
    'Remove this line if fixing active object other than buttons
    If ObjectSelected.progID = "Forms.CommandButton.1" Then
        ObjectSelected_Height = ObjectSelected.Height
        ObjectSelected_Top = ObjectSelected.Top
        ObjectSelected_Left = ObjectSelected.Left
        ObjectSelected_Width = ObjectSelected.Width
        ObjectSelected_FontSize = ObjectSelected.Object.FontSize

        ObjectSelected.Placement = 3

        ObjectSelected.Height = ObjectSelected_Height + 1
        ObjectSelected.Top = ObjectSelected_Top + 1
        ObjectSelected.Left = ObjectSelected_Left + 1
        ObjectSelected.Width = ObjectSelected_Width + 1
        ObjectSelected.Object.FontSize = ObjectSelected_FontSize + 1

        ObjectSelected.Height = ObjectSelected_Height
        ObjectSelected.Top = ObjectSelected_Top
        ObjectSelected.Left = ObjectSelected_Left
        ObjectSelected.Width = ObjectSelected_Width
        ObjectSelected.Object.FontSize = ObjectSelected_FontSize

    End If
Next

末端子组件

相关问题