Private Sub btnAddWorksheet_Click()
' variable for the tryAgain logic below
Dim tryAgain As Integer
' if the user leaves the box empty go to the error handler section
On Error GoTo errHandler
[Link] before:=Worksheets(1)
[Link] = InputBox("Please enter a new worksheet name")
' if no error skip the errHandler
Exit Sub
' error handler section
errHandler:
' prompt the user to try again
tryAgain = MsgBox("Invalid Worksheet Name", vbYesNo)
' if the user picked yes
If tryAgain = 6 Then
're-run the procedure
btnAddWorksheet_Click
Else
' turn off the alert of deleting the worksheet if the user selects no
[Link] = False
' delete the invalid worksheet
[Link]
End If
End Sub