【问题标题】:Excel checkbox in the center of cell单元格中心的 Excel 复选框
【发布时间】:2019-02-19 10:29:59
【问题描述】:

是否可以将复选框框移动到单元格的中心?我正在创建复选框。复选框本身在左侧,文本在右侧。我正在删除文本,所以只剩下“复选框”。我希望单元格的整个区域都是“可点击的”。因此,如果我调整字段大小,可点击区域会更小。有没有办法保持复选框的大小与单元格大小相同并将复选框框移动到中间/中心?就像文本一样,有一个按钮可以将文本定位在左侧、中间和右侧?

【问题讨论】:

    标签: excel checkbox position center


    【解决方案1】:

    非常简单。您必须获得要使复选框居中的单元格的TopLeft 位置。所以...

    Option Explicit
    
    Sub CenterMyCheckbox()
        Dim myCheckbox As Shape
        Set myCheckbox = ActiveSheet.Shapes("Check Box 1")
    
        Dim cbCell As Range
        Set cbCell = ActiveSheet.Range("B3")
    
        '--- this just positions the checkbox even with the top, left of the cell
        myCheckbox.left = cbCell.left
        myCheckbox.top = cbCell.top
    
        '--- this centers the checkbox vertically
        Dim cellHeight As Double
        Dim cbHeight As Double
        cellHeight = cbCell.Height
        cbHeight = myCheckbox.Height
        myCheckbox.top = cbCell.top + (cellHeight / 2#) - (cbHeight / 2#)
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2017-11-15
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 2019-03-19
      相关资源
      最近更新 更多