工作表上放置了几个事件控件(组合框、文本框和列表框)。这些形状也与单元格相关联。我需要调整形状的大小,使它们适合/对齐单元格大小。如何使用 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/