Thread: [Solved] TextBox / Shape name
View Single Post
 
Old 10-25-2014, 07:57 PM
excelledsoftware excelledsoftware is offline Windows 7 64bit Office 2003
IT Specialist
 
Join Date: Jan 2012
Location: Utah
Posts: 455
excelledsoftware will become famous soon enough
Default

I use this code snippet to name my shapes as well as get the name for them.

Code:
Sub Name()

  Dim sResponse As String

  With ActiveWindow.Selection.ShapeRange(1)
    sResponse = InputBox("new name ...", "Rename Shape", .Name)
    Select Case sResponse
     ' blank names not allowed
     Case Is = ""
       Exit Sub
     ' no change?
     Case Is = .Name
       Exit Sub
     Case Else
       On Error Resume Next
       .Name = sResponse
       If Err.Number <> 0 Then
         MsgBox "Unable to rename this shape"
       End If
    End Select
  End With

End Sub
I run this macro to a button on my toolbar and then just click it when I need the name of a shape. You could probably do something similar if you wanted a less bloated version. Maybe like

Code:
Sub name2()
  Dim x As String

  On Error Resume Next
  x = ActiveWindow.Selection.ShapeRange(1).name
  If x <> "" Then MsgBox x
  On Error GoTo 0
End Sub
Let me know Thanks
Reply With Quote