View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Macro needs to rename worksheet tab name

Hi Joe,

Try the following. Note the error trapping is essential. However, if
re-naming the first sheet with the same name then it does not produce an
error.

Sub ReNameWorksheet()
Dim strShtname As String

strShtname = "My New Sht Name"
On Error Resume Next
ThisWorkbook.Sheets(1).Name = strShtname
If Err.Number 0 Then
MsgBox "Cannot re-name worksheet." & vbLf _
& strShtname & " already exists."
End If
On Error GoTo 0
End Sub

--
Regards,

OssieMac