這可以在形狀工作表_Change
事件來實現。將此添加到Shapes
工作表vba
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim shp As Shape
Dim nw As Variant
Dim old As Variant
' in case there is an error...
On Error GoTo CleanUp
Set rng = Intersect(Target, [Shape])
If Not rng Is Nothing Then
' Save new name
nw = Target
' Prevent events firing while we change sheet values
Application.EnableEvents = False
' Get previous name
Application.Undo
old = Target
' Restore new name
Target = nw
' Rename selected Shapes
For Each shp In Me.Shapes
If shp.Name Like old & "#*" Then
shp.Name = nw & Mid(shp.Name, Len(old) + 1)
End If
Next
End If
CleanUp:
' Re-enable events
Application.EnableEvents = True
End Sub
謝謝,這真是太棒了...將修改使用第二列而不是數字字母? – Links
只需更改'shp.Name像舊的&##「'shp.Name像舊的&」*「。然後任何以舊名稱開頭的形狀名稱將被更改 –
如果這解決了您的問題,您應該接受答案(請單擊打勾) –