你可以使用一个函数返回最宽的形状,并设置其宽度也
Function GetWidestShape(widestShpWidth As Long) As Shape
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Width > widestShpWidth Then
widestShpWidth = shp.Width
Set GetWidestShape = shp
End If
Next
End Function
,你可以在你的主代码漏洞如下:
Sub Main()
Dim widestShp As Shape
Dim widestShpWidth As Long
Set widestShp = GetWidestShape(widestShpWidth) '<--| get the widest shape along with ist width
With widestShp
' ...
' your code to act on referenced shape
'...
End With
End Sub
当然双的做法也是可以的:
Function GetWidestShapeWidth(widestShp As Shape) As Long
Dim shp As Shape
Dim widestShpWidth As Long
For Each shp In ActiveSheet.Shapes
If shp.Width > widestShpWidth Then
widestShpWidth = shp.Width
Set widestShp = shp
End If
Next
End Function
Sub Main()
Dim widestShp As Shape
Dim widestShpWidth As Long
widestShpWidth = GetWidestShapeWidth(widestShp) '<--| get the width of the widest shape along with the widest shape
With widestShp
' ...
' your code to act on referenced shape
'...
End With
End Sub
欢迎来到Stackoverflow!在发布问题时,请分享您的代码,并尝试尽可能好地解释您的问题。现在,你所要求的东西很不清楚。 –
这个问题的确切部分是你有麻烦吗? –
嗨,再次。对不起,在问题中不太清楚。这里是一段代码,以更好地解释 – user7381321