Hi,
In my production workbook I've got code similar to the following excerpt:
'==============================================================================
' WORKSHEET ACTIVATION
'==============================================================================
' The actual event routines must be in a standard module for "Application.Run" to work properly
Private Sub Wkb_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
Case "MemberInfo"
MemberInfo_Activate Sh
Case "Cases"
Cases_Activate Sh
Case "Claims"
Claims_Activate Sh
Case "Letters"
Letters_Activate Sh
Case "Payments"
Payments_Activate Sh
Case "Money"
Money_Activate Sh
Case "FutureMedical"
FutureMedical_Activate Sh
Case "Notes"
Notes_Activate Sh
Case "Lawyers"
Lawyers_Activate Sh
Case "CaseSummary"
CaseSummary_Activate Sh
Case "CaseDetails"
CaseDetails_Activate Sh
Case "CaseHistory"
CaseHistory_Activate Sh
Case "Dashboard"
Dashboard_Activate Sh
Case "Lookups"
Lookups_Activate Sh
Case Else
' MsgBox Sh.Name & " is an unknown worksheet name. Please see your Midas Administrator."
' Nothing...
End Select
End Sub
Private Sub Money_Activate(ByVal Sh As Object)
ProtectWorksheet
Application.Calculate
End Sub
' Protect only if not already protected.
' RUNNING THE PROTECT METHOD CLEARS THE CLIPBOARD,
' MAKING IT IMPOSSIBLE TO PASTE INTO THIS WORKSHEET.
Sub ProtectWorksheet()
With ActiveSheet
If Not .ProtectContents Then ' DO NOT REMOVE THIS LINE!!!
.Protect _
Password:="", _
AllowSorting:=True, _
AllowFiltering:=True, _
UserInterFaceOnly:=True
.EnableSelection = xlNoRestrictions
End If ' DO NOT REMOVE THIS LINE!!!
End With
End Sub
So, in most cases, activating a worksheet re-protects the worksheet (UserInterfaceOnly) if it's not already protected. Note: the protection is just meant to keep the end user from shooting him/herself in the foot. There is no password on the worksheet protection; the end user can unprotect the worksheet if needed.
I thought conditionally executing the protection would keep the clipboard intact, but this doesn't appear to be the case.
What's irritating the end user is the inability to copy a cell value from one worksheet to another, in particular to the Money tab. When he clicks on the Money tab, the worksheet gets re-protected (if necessary), and the formulas are re-calculated. At which point the clipboard is empty, and he can't copy into the Money worksheet.
Why does executing VBA clear the clipboard - surely Microsoft could fix this??? Is there any workaround for this issue short of re-architecting my application?
Thanks,
Scott
P.S.: The reason it's coded this way is the vast bulk of the code is in a class module in an XLAM add-in. This approach was the only way I could get it to work. It's klunky but functional (and ultimately off-topic to my main question).
Bookmarks