简体   繁体   English

如何在不选择形状的情况下使用VBA更改Excel中的文本大小?

[英]How can I change the text size in Excel using VBA without selecting the shape?

I am trying to change the text size in a textbox in Excel using VBA. 我试图使用VBA更改Excel中文本框中的文本大小。 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! 谢谢!

As @findwindow says: 正如@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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM