Clearing Clipboard in Excel 2013 VBA

melson titular

New Member
Joined
Oct 3, 2013
Messages
43
Hello guys.,

i have found this code and tried it out.,
upon checking., it seems it is applicable only for 2004 and below excel versions.
is there other way to clear the clipboard in excel 2013?

Option Explicit
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Function ClearClipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Function
Sub Test()
Call ClearClipboard
End Sub

regards, melson
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This will clear your clipboard.

Code:
Sub ClearClipboard()
    Dim DataObj As New MSForms.DataObject
    DataObj.SetText ""
    DataObj.PutInClipboard
End Sub

I was messing around playing with the clipboard just the other day, here are the two modules I filed away for the day I may need them :)

Code:
Sub PutInClipboard()
    Dim DataObj As New MSForms.DataObject
    Dim S As String
    S = "Hello World"
    DataObj.SetText S
    DataObj.PutInClipboard
End Sub

Sub GetFromClipboard()
    Dim DataObj As New MSForms.DataObject
    Dim S As String
    DataObj.GetFromClipboard
    S = DataObj.GetText
    Debug.Print S
End Sub
 
Upvote 0
i am using windows.,
i got an error on this line. user-defined type not defined.
Dim DataObj As New MSForms.DataObject
You need to set reference on VBE: Tools -> References -> Microsoft Forms 2.0 Object Library.
 
Upvote 0
You need to set reference on VBE: Tools -> References -> Microsoft Forms 2.0 Object Library.

hi sektor,

thanks., yes, i have checked Microsoft Forms 2.0 Object Library and executed the code.,
this time., i did not get the user-defined type not defined error , but my clipboard is still not cleared up.

regards, melson
 
Upvote 0
Try:
Code:
Application.CutCopyMode = False
 
Upvote 0
Hi sektor,

sorry but clipboard still not cleared.

Sub ClearClipboard()

Dim DataObj As New MSForms.DataObject
DataObj.SetText ""
DataObj.PutInClipboard

Application.CutCopyMode = False

End Sub
 
Upvote 0
GTO, you asking Me or the OP?

Sorry Blade Hunter, I was too brief. I meant the OP, as I am unaware of anything WIN Office in 2004.

@Melson:

I just tested quickly against:
  • copy a cell (select the cell and Ctrl +C)
  • copy value inside of cell (F2 and select string; Ctrl + C)
  • copy string from a text editor


In all three case, this dumps the clipboard:

Code:
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
  
Sub test()
  OpenClipboard (0&)
  EmptyClipboard
  CloseClipboard
End Sub

I am currently running in WIN7 with Excel2010. Might there be something different in your actual code?

Mark
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top