excel - 单元格中心的 Excel 复选框
问题描述
是否可以将复选框框移动到单元格的中心?我正在创建复选框。复选框本身位于左侧,文本位于右侧。我正在删除文本,所以只剩下“复选框”。我希望单元格的整个区域都是“可点击的”。因此,如果我调整字段大小,可点击区域会更小。有没有办法保持复选框的大小与单元格大小相同并将复选框框移动到中间/中心?就像文本一样,有按钮可以将文本定位在左侧、中间和右侧?
解决方案
很简单。您必须获取要使复选框居中的单元格的Top
和Left
位置。所以...
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
推荐阅读
- python - 并行化 DataFrame 自定义函数 Dask
- tensorflow - 无法将生成器从 estimator.predict 转换为列表
- javascript - Javascript:无法读取未定义的属性“长度”
- python-3.x - 在 P4 中,我如何使用命令检查提交到一个分支的更改是否也提交到另一个分支
- r - 我无法在 R 中安装包 tcltk
- java - 如何在不出现 StackOverflowError 的情况下删除静态?
- javascript - 使用 javascript 使用 iframe 时如何打开新选项卡
- docker - 如何使用 docker 容器创建 vsftpd 服务器?
- javascript - 需要帮助尝试在本机反应中刷新我的令牌
- excel - Excel:创建宏以将活动选择复制并粘贴到另一个工作表中