你可以使用一個函數返回最寬的形狀,並設置其寬度也
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