Results 1 to 2 of 2

Clipboard gets emptied when VBA runs

Threaded View

  1. #1
    Registered User
    Join Date
    01-10-2014
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2007
    Posts
    77

    Clipboard gets emptied when VBA runs

    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).
    Last edited by scottbass; 04-23-2014 at 12:33 AM. Reason: Added explanation for coding approach

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Prevent clipboard from emptying with macro that runs on deactivate
    By CDEG in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2014, 08:52 AM
  2. Formula to account for skids of boxes being emptied then refilled
    By les0341 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-19-2014, 11:26 AM
  3. Replies: 0
    Last Post: 02-06-2013, 01:55 PM
  4. Protect clipboard data from other programs trying to use clipboard at same time?
    By chuckchuckit in forum Excel Programming / VBA / Macros
    Replies: 28
    Last Post: 09-25-2010, 07:25 AM
  5. clipboard cannot be emptied
    By rroach in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1