我正在使用Excel 2013并创建了一些宏,目前我们正在将它们嵌入到文本框中。我如何创建一个宏来获取选定的文本框并使它们居中并调整它们的大小以使它们完全适合它们所在的单元格。
Sub TextBox2Cell()
With ActiveCell
ActiveSheet.Shapes.AddTextbox _
msoTextOrientationHorizontal, .Left, _
.Top, .Width, .Height
End With
End Sub
我有这个代码来创建新的文本框,但需要使用已经创建的文本框。
答案 0 :(得分:3)
您可以参考每个文本框的.TopLeftCell
属性而不是ActiveCell
,然后运行这样的子例程来调整每个文本框维度以匹配基础单元格的维度:< / p>
Sub ResizeAllTextBoxes()
Dim cl As Range
Dim tb As textbox
For Each tb In ActiveSheet.TextBoxes
Set cl = tb.TopLeftCell
With cl
tb.Height = .Height
tb.Width = .Width
tb.Left = .Left
tb.Top = .Top
End With
Next
End Sub
答案 1 :(得分:0)
如果您想将文本框添加到activecell,则:
Sub CoverRange()
Dim r As Range
Dim L As Long, T As Long, W As Long, H As Long
Set r = ActiveCell
L = r.Left
T = r.Top
W = r.Width
H = r.Height
With ActiveSheet.Shapes
.AddTextbox(msoTextOrientationHorizontal, L, T, W, H).Select
End With
End Sub