On a worksheet I have multiple shapes and several buttons attached to simple macros which manipulate the shapes: eg rotate, flip etc.
Also attached to each button is a procedure to handle the error that occurs if a shape has not first been selected. (I will show the code below.)
The problem I want to address is the repetitiveness of my code: Every simple macro is imbedded in the same lengthy error-checking code. How can I approach this in a more concise way?
Currently I am writing this whole thing around every simple one line instruction.
Thanks in advance.
(I got this code from The Spreadsheet Guru website)
Also attached to each button is a procedure to handle the error that occurs if a shape has not first been selected. (I will show the code below.)
The problem I want to address is the repetitiveness of my code: Every simple macro is imbedded in the same lengthy error-checking code. How can I approach this in a more concise way?
Code:
Sub Rotate90 ()
Dim ActiveShape As Shape
Dim UserSelection As Variant
Set UserSelection = ActiveWindow.Selection
On Error GoTo NoShapeSelected
Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)
On Error Resume Next
Selection.ShapeRange.IncrementRotation 90
Exit Sub
Error handler
NoShapeSelected:
MsgBox "You do not have a shape selected "
End Sub
Currently I am writing this whole thing around every simple one line instruction.
Thanks in advance.
(I got this code from The Spreadsheet Guru website)