Reputation: 43
I am trying to change the text size in a textbox in Excel using VBA. I currently have the following code:
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
This code animates the text increasing in size, and then it disappears. The problem is that when I run this code the textbox is selected (there is a box around it). How can I achieve the same goal without selecting the textbox/showing the selection border around it?
Thanks!
Upvotes: 1
Views: 2536
Reputation: 43
I found a solution. I had to set the textbox as a shape variable, and then adjust it.
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
Upvotes: 1
Reputation: 166126
As @findwindow says:
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
Upvotes: 2