我希望在Excel中使用VBA的文本框如下所示:

RGB(0,112,192) (蓝色)中的测试框中的
我已经创建了这段代码,但我不知道如何编程。
Sub TextBox()
Set myDocument = Worksheets(1)
myDocument.Shapes.AddTextBox(msoTextOrientationHorizontal, _
100, 100, 200, 50) _
.TextFrame.Characters.Text = "Test Box of how I would like it"
End Sub有人能帮我吗?
发布于 2020-06-30 21:09:31
如果您在设置线宽、线条颜色和文本颜色时打开宏记录器,您将找到用于此操作的代码。
With Selection.ShapeRange.Line
.Weight = 1.5
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
End With
With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 11).Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 112, 192)
.Transparency = 0
.Solid
End With发布于 2020-06-30 23:11:47
在定义变量和编码之后,它有助于编写代码。
Sub TextBox()
Dim myDocument As Worksheet
Dim Shp As Shape
Dim s As String
Set myDocument = Worksheets(1)
Set Shp = myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 50)
With Shp
With .TextFrame
s = "Test Box of how I would like it"
.Characters.Text = s
.Characters(1, Len(s)).Font.Color = RGB(0, 112, 193)
End With
.Line.Weight = 1.5
.Line.ForeColor.RGB = RGB(0, 112, 193)
End With
End Subhttps://stackoverflow.com/questions/62665983
复制相似问题