我正在尝试使用VBA更改Excel中文本框中的文本大小。我目前有以下代码:
ActiveSheet.Shapes.Range(Array("textEnemy")).Visible = True
ActiveSheet.Shapes.Range(Array("textEnemy")).Select
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters
.Text = msg
For i = 1 To 15
.Font.Size = i * 10
Call WasteTime(50)
Next
End With
ActiveSheet.Shapes.Range(Array("textEnemy")).Visible = False
此代码会动画文本大小增加,然后消失。问题是,当我运行此代码时,文本框被选中(周围有一个框)。如何在不选择文本框/显示其周围的选择边框的情况下实现相同的目标?
谢谢!
答案 0 :(得分:2)
正如@findwindow所说:
With ActiveSheet.Shapes.Range(Array("textEnemy"))
.Visible = True
With .ShapeRange(1).TextFrame2.TextRange.Characters
.Text = msg
For i = 1 To 15
.Font.Size = i * 10
Call WasteTime(50)
Next
End With
.Visible = False
End With
答案 1 :(得分:1)
我找到了解决方案。我必须将文本框设置为形状变量,然后进行调整。
Sub Animate(playerCode As Integer)
Dim i As Integer
Dim msg As String
Dim textBox As Shape
msg = "HIT!"
Set textBox = ActiveSheet.Shapes("textUser")
'Animate textbox
textBox.Visible = True
With textBox.TextFrame2.TextRange.Characters
.Text = msg
For i = 1 To 15
.Font.Size = i * 10
Call WasteTime(50)
Next
End With
textBox.Visible = False
End Sub