我有以下在网上找到的例程:http://www.ozgrid.com/forum/showthread.php?t=77662
这个例程不起作用因为我不知道形状名称。有人能告诉我矩形框的形状名称是什么吗?
Function SetShapeText(s As String, sShpName As String)
s = "some text"
Dim i As Integer
ActiveSheet.Shapes(sShpName).Select
With Selection
.Text = ""
For i = 0 To Int(Len(s) / 255)
.Characters(.Characters.Count + 1).Text = Mid(s, 255 * i + 1, 255)
Next
End With
End Function
它在此行出错:ActiveSheet.Shapes(sShpName).Select
答案1
您需要运行第一个来获取名称。这里的第二个向您展示如何调用那里的函数。
Sub myshapes()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
Debug.Print shp.Name
Next
End Sub
Sub sendit()
Dim shpnm As String
shpnm = "Rectangle 1"
Dim mystring As String
mystring = "blah blah"
Dim x As Variant
x = SetShapeText(mystring, shpnm)
End Sub
你看,那里有一个需要两个输入的函数:s,sShpName
要使用函数,您需要像上面一样调用它并向其中传递参数。无需更改函数内的任何内容。