excel - 使工作表中的 ActiveX 控件适合单元格大小

标签 excel vba

工作表上放置了几个事件控件(组合框、文本框和列表框)。这些形状也与单元格相关联。我需要调整形状的大小,使它们适合/对齐单元格大小。如何使用 VBA 执行此操作?

最佳答案

下面介绍如何调整 ActiveX 控件的高度和宽度。我以 textBox 为例

Dim rng As Range

With [Sheet1] '<~~ Change this to the relevant sheet
    Set rng = .Range(.TextBox1.LinkedCell)

    .TextBox1.Width = rng.Width
    .TextBox1.Height = rng.Height
End With

评论的跟进。

As I stated earlier, there are several different types of ActiveX controls in the sheet. I am looking for generic code that will loop through the Shapes collection (without specifically naming the shapes) and align the shape sizes to those of the linked cells. – user1955215 12 mins ago



如果你想使用形状然后使用它。
Dim rng As Range
Dim shp As Shape

With ActiveSheet
    Set shp = .Shapes("TextBox1")

    Set rng = .Range(shp.OLEFormat.Object.LinkedCell)

    shp.Width = rng.Width
    shp.Height = rng.Height
End With

关于excel - 使工作表中的 ActiveX 控件适合单元格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21551405/

相关文章:

vba - 根据 VBA 中的 If 语句插入箭头

arrays - 无法使用数组成员变量分配数组

excel - VBScript 打开 Excel 文件,然后执行另存为

vba - 使用VBA在excel中导入网页数据

Excel VBA 迭代文件 - 陷入循环

excel - 如何在 vba excel 中执行 Do Event 计时器,同时仍然能够更改工作表中的值?

xml - 如何通过 VBA 读取和修改 XML 文件?

excel - 通过电子邮件发送事件工作簿的压缩版本

excel - 如果整行使用 VBA 匹配,则删除重复的行

VBA VisibleCell 不可见