Reset Clear ClipBoard

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
[FONT=&quot]Hello everyone[/FONT]
[FONT=&quot]I have searched a lot and tried a lot of codes for clearing the clipboard and this is one of them
Code:
[/FONT][/COLOR][COLOR=#2E8B57][FONT=Monaco]Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Public Declare Function EmptyClipboard Lib "user32" () As Long[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]Public Declare Function CloseClipboard Lib "user32" () As Long[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]Public Function ClearClipboard()[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    OpenClipboard (0&)[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    EmptyClipboard[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    CloseClipboard[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]End Function[/FONT][/COLOR]

[COLOR=#2E8B57][FONT=Monaco]Sub Test()[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]    Call ClearClipboard[/FONT][/COLOR]
[COLOR=#2E8B57][FONT=Monaco]End Sub[/FONT][/COLOR][COLOR=#333333][FONT=&quot]

[/FONT]
[FONT=&quot]But nothing works for me till now[/FONT]
[FONT=&quot]Any idea?

I have posted this thread at this link
[/FONT]
http://www.eileenslounge.com/viewtopic.php?f=30&t=31849

But I didn't find a solution till now

I am using Office 2016 32 Bit
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi YasserKhalil

When you say nothing works for me, what exactly do you mean ? Are you getting an error or what ?

Also, Are we talking about the Office Clipboard or the Windows legacy clipboard ?

Regards.

 
Last edited:
Upvote 0
Thanks a lot of reply
Most of the codes I have tested I didn't get any errors at all but at the same time when opening the clipboard window I found all the contents of the clipboard are still there ..
I am talking about the Office Clipboard
I mean the window which I can open from Home Tab in excel
 
Upvote 0
Can you give this a try :
Code:
Option Explicit

[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  VBA7 Then
    Declare PtrSafe Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
    Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If


Sub ClearOfficeClipBoard()
    Dim avAcc, bClipboard As Boolean, j As Long
    
    Set avAcc = Application.CommandBars("Office Clipboard")
        bClipboard = avAcc.Visible
        If Not bClipboard Then
            avAcc.Visible = True
            DoEvents
        End If
        For j = 1 To 4
            AccessibleChildren avAcc, Choose(j, 0, 3, 0, 3), 1, avAcc, 1
        Next
        avAcc.accDoDefaultAction 2& '1& for paste
        Application.CommandBars("Office Clipboard").Visible = bClipboard
End Sub
 
Upvote 0
Thanks a lot for reply

I have tested the code and I got the Clipboard window open then I got Invalid procedure call (Error '5') at this line
Code:
avAcc.accDoDefaultAction 2& '1& for paste
 
Upvote 0
Strange ! Are you using an arabic edition of office ?

Try experimenting with :

avAcc.accDoDefaultAction 0&

and if the above doesn't work try this :

avAcc.accDoDefaultAction 1&
 
Upvote 0
Thank you very much for your patience. I tried 1& and this throws error too ...
Then I tried &0 and this doesn't throw any error .. But when have a look at the clipboard, I found it not clear

I am using Office 2016 32Bit (English version) and this is a snapshot of the Clipboard

 
Last edited:
Upvote 0
Can you run this and tell us the output you get in the immediate window :

Code:
Option Explicit

[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  VBA7 Then
    Declare PtrSafe Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
    Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As Office.IAccessible, ByVal iChildStart As Long, ByVal cChildren As Long, ByRef rgvarChildren As Any, ByRef pcObtained As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If


Sub ClearOfficeClipBoard()
    Dim avAcc, bClipboard As Boolean, j As Long
    
    Set avAcc = Application.CommandBars("Office Clipboard")
        bClipboard = avAcc.Visible
        If Not bClipboard Then
            avAcc.Visible = True
            DoEvents
        End If
        For j = 1 To 4
            AccessibleChildren avAcc, Choose(j, 0, 3, 0, 3), 1, avAcc, 1
        Next
        avAcc.accDoDefaultAction 2& '1& for paste
        
    Dim a As IAccessible
    Dim i As Long
    
    Set a = avAcc
    For i = 0 To a.accChildCount
        Debug.Print i & vbTab & a.accName(i)
    Next
        
    Application.CommandBars("Office Clipboard").Visible = bClipboard
End Sub
 
Upvote 0
I have changed 2& to 0& to avoid error then I got 0 at the immediate window and then another error at this part
Code:
a.accName(i)
In valid procedure call or argument
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,098
Members
453,021
Latest member
Justyna P

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