Results 1 to 3 of 3

VBA code to clear the Windows clipboard (better than application.cutcopymode = false)

Threaded View

  1. #1
    Registered User
    Join Date
    03-31-2020
    Location
    Missouri USA
    MS-Off Ver
    Office 365
    Posts
    3

    VBA code to clear the Windows clipboard (better than application.cutcopymode = false)

    I have a bunch of excel macros running back-office functions, and my users were accidentally copying out data that had been copied by VBA macros into other places (this is not good).
    I did some googled and found the typical "just use application.cutcopymode = false" answer all over the internet.

    Unfortunately this does not work, at least not in Windows 10 with Excel in office 365, so I had to be creative.

    I found a good starting place on this post: vbaexpress.com/kb/getarticle.php?kb_id=205
    This pointed me in the right direction, and after some small changes I found a way to clear my clipboard every time.

    Here is the code, with my comments:

    'THE CODE BELOW WAS CREATED AND PUT IN ALL TRACKERS TO STOP USERS FROM COPYING OUT CONFIDENTIAL DATA ACCIDENTALLY
    'IT WORKS BY CLEARING THE WINDOWS CLIPBOARD ENTIRELY

    Option Explicit
    
        Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
        Private Declare Function EmptyClipboard Lib "user32" () As Long
        Private Declare Function CloseClipboard Lib "user32" () As Long
    
    Private Function ClearClipboard()
    
        OpenClipboard (0&)
        EmptyClipboard
        CloseClipboard
    
    End Function
    
    'TO CALL THE CODE, JUST PUT THE FUNCTION NAME WHEREVER YOU NEED IT IN A MACRO:
    
    Private Sub whatever()
        
        blahblahblah
        ClearClipboard
    
    End Sub
    Last edited by alansidman; 07-09-2020 at 03:31 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] After Range.Copy Paste and Application.CutCopyMode = False, Range still remains selected
    By badcluster in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-03-2020, 06:18 AM
  2. [SOLVED] ClipBoard Not Clearing: #Application.CutCopyMode=False#
    By TFiske in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-26-2018, 01:43 PM
  3. [SOLVED] Application.CutCopyMode=False
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-12-2017, 10:43 PM
  4. [SOLVED] Application.CutCopyMode
    By Chatters in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-10-2013, 04:40 PM
  5. DisplayFormulaBar = false seems to clear clipboard
    By oCoCarbon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2010, 07:05 AM
  6. [SOLVED] Can't paste when CutCopyMode is false even though clipboard is not
    By Paul628 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-05-2006, 02:45 PM
  7. Why is Application.CutCopyMode False?
    By Gary''s Student in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2006, 06:15 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