Share via

excel vba clear clipboard

Anonymous
2020-05-29T05:26:48+00:00

I am running Office 365 Home using Windows 10. I want to clear the clipboard programatically. I have tried to record a macro but this does not create any code. From the help system

I get  a code snippet "My.Computer.Clipboard.Clear()" which results in "Compile error = expected". I tried substituting my.computer. with application. but no joy. Help!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

20 answers

Sort by: Most helpful
  1. Anonymous
    2020-09-14T16:17:39+00:00

    I think (keyword think) I figured this out (finally).  I'm running on Win10 and had no problems with Office (2007) until last week.  Last week I had to reinstall the OS from scratch, and since then I've been getting the pesky "cannot empty clipboard" error.  Before and after software was the same, just a new install.

    However, I just realized that I might have had to use Office before changing the Win10 settings to turn off the clipboard history.  What I just found was that while I currently had the Clipboard History off, I was using the "normal" >ctrl<-V history.  But, there were still items in the Win10 history file!  And, my thoughts are that this is what the "cannot empty clipboard" error is referring to!

    If true, then the solution is simple;

    • Open Windows 10 Clipboard History settings
    • >Windows Key<
    • Type "Clipboard"; "Clipboard settings usually appears at the top of the list by the letter "i".
    • Set Clipboard History ON or OFF as you want it
    • From that I've been able to find online, if you have History ON you are not getting this error.
    • If you turned History OFF
    • Open Microsoft Excel (since this is where the error is most consistent)
    • Press >Windows Key<-V to open the new clipboard history
    • MANUALLY delete all of the entries in the Clipboard history

    Since I've done this, I have not received the "unable to empty clipboard" error.  Of course, it may come back later if something else was contributing to the error or if a Windows 10 Update may do something to bring it back .

    Hope this helpeds

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2020-05-29T10:04:31+00:00

    For a while I thought that CutCopyMode = False acted to clear the clipboard but apparently it just removes the border marking the copied cell(s). I do want to remove all data from the clipboard. It is not super important but does save users from being asked if the data on the the clipboard is required when closing the workbook. I'll be delighted to receive the necessary code.

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2020-05-29T05:31:36+00:00

    Hello michaelcoltart

    I am V. Arya, Independent Advisor, to work with you on this issue. In case you are looking to clear Excel VBA clipboard, use following VBA statement

    Application.CutCopyMode = False

    If you need to clear Windows clipboard, let me know. There are few lines of code to be executed.

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  4. Anonymous
    2020-08-06T22:56:23+00:00

    To Michael Coltart

    re: any luck?

    I'm also running into the same exact issue. I scoured many forums which simply suggest minor variations to what has already been discussed previously. Yet my excel (Office 365) clipboard does not clear after i apply the various suggested VBA code snippets. 

    I've even tried the following to no avail:

    Option Explicit

    Private Declare PtrSafe Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long

    Private Declare PtrSafe Function EmptyClipboard Lib "User32" () As Long

    Private Declare PtrSafe Function CloseClipboard Lib "User32" () As Long

    Sub ClearClipboard()

        If OpenClipboard(0) Then

        EmptyClipboard

        CloseClipboard

        End If

    End Sub   

    I'm really at a loss for ideals, solutions.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  5. Anonymous
    2020-06-01T09:15:39+00:00

    HI Diana

    Thanks for your response. I'm hoping that I'm getting near to a solution but need to clarify a couple of points.

    • I have been running some tests with a sub similar to the Sub you describe but can't get to grips why it might help. There is no indication that this Sub is fired when the workbook is closed. Clearly it can be called from another Sub in the project but I could just as well simply have Application.CutCopyMode = False as a line in my code. I'm obviously missing something! I have designed some projects using Userforms and am used to the concept of being able to encode events that are fired by mouse clicks, entering or leaving objects etc and this may be why I can't undersand the current situation.
    • I'm confused by what you say regarding the Clipboard(s). My understanding is that there are 2 Clipboards. An MS Office Clipboard and a System Clipboard. It would appear this is a simplification. Have you time to to give me a more in depth description of what you mean by "an advanced way to trick Excel and actually dump data into the clipboard"?
    • What's the meaning of "taking Excel out of Linking Mode"?

    Michael Coltart

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments