sparky2205
Well-known Member
- Joined
- Feb 6, 2013
- Messages
- 507
- Office Version
- 365
- 2016
- Platform
- Windows
Hi folks,
I have the following macro which allows the copying of worksheets on a protected workbook.
It works fine but I was trying to replace:
with something like
In essence I want to retrieve the worksheet name using the codename.
Is this something straightforward?
I have the following macro which allows the copying of worksheets on a protected workbook.
It works fine but I was trying to replace:
Code:
sInterimName = ActiveSheet.Name
Code:
sc = Worksheets.Count
sInterimName = "Sheet" & sc.Name
Is this something straightforward?
Code:
Sub CopySheet()
Dim sName As String
Dim sInterimName As String
Dim iCountName As Integer
Dim ws As Worksheet
Dim pw As String
Dim sc As Integer
pw = ""
ScreenUpdating = False
iCountName = 0
sName = InputBox("Enter the worksheet name to copy")
If sName = "" Then
Exit Sub
End If
For Each ws In ThisWorkbook.Worksheets
If UCase(ws.Name) = UCase(sName) Then
iCountName = iCountName + 1
End If
Next ws
If iCountName = 0 Then
MsgBox "The selected worksheet name does not exist in this file"
Exit Sub
End If
ThisWorkbook.Unprotect Password:=pw
Sheets(sName).Copy after:=Sheets(sName)
sInterimName = ActiveSheet.Name
ThisWorkbook.Protect Password:=pw, structure:=True
Worksheets(sInterimName).Protect Password:=pw, _
userinterfaceonly:=True, _
AllowFiltering:=True, _
AllowFormattingCells:=True, _
AllowFormattingRows:=True, _
AllowFormattingColumns:=True, _
AllowInsertingRows:=True
ScreenUpdating = True
End Sub
Last edited: