I am using Excel 2007 and I need to disable Rename Sheet functionality in an Excel Workbook. I cannot protect the workbook because workbook is macro-enabled (xlsm) and when I protect the workbook, I get a Security Warning; Macros have been disabled and under Options I cannot enable the content. So I need to disable rename sheet without using workbook protection method.
I executed the following code mentioned in faq707-4727:
I copied this code in Module1 and pressed F5. Under CommandBar=Ply, Control=&Rename; id number is 889. I wrote the following in Workbook Open and BeforeClose:
Now when I right-click Sheet Name, Rename option is disabled. But Format -> Organize Sheets -> Rename Sheet is still enabled. Also, sheet can be renamed by double-clicking on Sheet Name. I also added the following on Sheet Deactivate:
It partially solves the problem that if sheet is renamed inadvertently, then it will get its name again. But the very fact that user is able to rename the sheet is making end-users unhappy.
I watched the video available at this link:
It shows a way for Microsoft Word, where clicking Macros in Developer tab and selecting Word Commands, the default behavior can be overridden but such option is not available in Excel 2007.
I executed the following code mentioned in faq707-4727:
Code:
Sub ListXLPopups()
Dim cbCtl As CommandBarControl
Dim cbBar As CommandBar
Dim i As Integer
On Error Resume Next
Application.ScreenUpdating = False
Cells(1, 1).Value = "CommandBar"
Cells(1, 2).Value = "Control"
Cells(1, 3).Value = "FaceID"
Cells(1, 4).Value = "ID"
i = 2
For Each cbBar In CommandBars
Application.StatusBar = "Processing Bar " & cbBar.Name
If cbBar.Type = msoBarTypePopup Then
Cells(i, 1).Value = cbBar.Name
i = i + 1
For Each cbCtl In cbBar.Controls
Cells(i, 2).Value = cbCtl.Caption
cbCtl.CopyFace
If Err.Number = 0 Then
ActiveSheet.Paste Cells(i, 3)
Cells(i, 3).Value = cbCtl.FaceId
End If
Cells(i, 4).Value = cbCtl.ID
Err.Clear
i = i + 1
Next cbCtl
End If
Next cbBar
Range("A:B").EntireColumn.AutoFit
Application.StatusBar = False
End Sub
I copied this code in Module1 and pressed F5. Under CommandBar=Ply, Control=&Rename; id number is 889. I wrote the following in Workbook Open and BeforeClose:
Code:
Private Sub Workbook_Open()
Application.CommandBars("Ply").Controls("Rename").Enabled = False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Ply").Controls("Rename").Enabled = True
End Sub
Now when I right-click Sheet Name, Rename option is disabled. But Format -> Organize Sheets -> Rename Sheet is still enabled. Also, sheet can be renamed by double-clicking on Sheet Name. I also added the following on Sheet Deactivate:
Code:
Private Sub Worksheet_Deactivate()
Me.Name = "Sheet1"
End Sub
It partially solves the problem that if sheet is renamed inadvertently, then it will get its name again. But the very fact that user is able to rename the sheet is making end-users unhappy.
I watched the video available at this link:
It shows a way for Microsoft Word, where clicking Macros in Developer tab and selecting Word Commands, the default behavior can be overridden but such option is not available in Excel 2007.