Option Explicit
Public sSheetToEdit As String
Public lMyWorksheetNumber As Long
Public Const EDIT_MSG_STARTS_AT = "C1"
Public Const CMD_RETURN_TO_SUMMARY_LOC = "H1"
Public Const PW ="Abnormal"
Sub EditSelectedWorksheet(ByVal sSheetToEdit As String)
Application.SendKeys Keys:="{F2}"
'Hide all the other worksheets except the one being edited
Call MakeSheetsInvisible
'hide the form
frmScopeHeader.Hide
'lock down the worksheet were editing, sSheetToEdit
Call LocKDownAll
'unlock the edit area ...all material workbooks have a data entry area
ThisWorkbook.Worksheets(sSheetToEdit).Range("Data_Entry").Unprotect Password:=PW
'warn the user they are in edit mode
Call PostEditModeMessage 'maybe locate the message relative to the data_entry area?
'Create a buttom to get back to the Summary sheet after the edit is over
Call CreateReturnToSummaryButton
'And the edit session is underway
ThisWorkbook.Worksheets(sSheetToEdit).Activate
'wait for the user to complete his entry
'transfer the Breakdown range to Scope
'Get back to the form on ScopeSheet.
End Sub
Sub MakeSheetsInvisible()
Dim i As Long, _
lMyWorksheetNumber As Long
lMyWorksheetNumber = Mid(sSheetToEdit, 1, 1)
For i = 1 To ThisWorkbook.Worksheets.Count
If Mid(ThisWorkbook.Worksheets(i).Name, 1, 1) <> lMyWorksheetNumber Then
ThisWorkbook.Worksheets(i).Visible = False
End If
Next i
End Sub
Sub LocKDownAll()
' SelectAndLocKDownAll Macro
ActiveCell.Cells.Select
ActiveSheet.Protect Password:=PW, DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub PostEditModeMessage()
ActiveCell.Offset(0, 3).Range(EDIT_MSG_STARTS_AT).Select
ActiveCell.FormulaR1C1 = "Please Note You Are in Edit Mode"
ActiveCell.Select
With Selection.Font
.FontStyle = "Bold"
.Size = 14
.Color = 255
End With
Selection.MergeCells = True
End Sub
Sub CreateReturnToSummaryButton()
ActiveCell.Offset(0, 1).Range(CMD_RETURN_TO_SUMMARY_LOC).Select
ActiveSheet.Buttons.Add(388.5, 0.75, 185.25, 33.75).Select
Selection.OnAction = "RestoreSourceAfterEdit" 'name of the macro to run
Selection.Characters.Text = "Return To Scope Sheet" 'caption
Selection.Characters.Name = "CommandButton1" 'not sure there is any such thing
With Selection.Characters(Start:=1, Length:=21).Font
.FontStyle = "Regular"
.Size = 11
.ColorIndex = 1
End With
End Sub
Sub CommandButton1_Click()
' Leave Edit Mode
SendKeys "+{F2}"
' Erase the Edit Mode Warning message
ThisWorkbook.Worksheets(sSheetToEdit).Range(EDIT_MSG_STARTS_AT).Value = ""
' Make worksheets visible again
Call ShowAllWorksheets
' Unlock the cells
ActiveSheet.Unprotect PW
' Hide or delete the OK Button and the warning message
ActiveSheet.Shapes("CommandButton1").Delete
' Update Summary with the refreshed values from Target
frmScopeHeader.Show
Call CopyTheBreakdown(sSheetToEdit)
ThisWorkbook.Worksheets("Summary").Activate
End Sub
Sub ShowAllWorksheets()
Dim i As Long, _
MyWorksheetNumber As Long, _
wksht As Worksheet
MyWorksheetNumber = Mid(ThisWorkbook.ActiveSheet.Name, 1, 1)
For i = 1 To ThisWorkbook.Worksheets.Count
ThisWorkbook.Worksheets(i).Visible = True
Next i
End Sub