Continued from last post…..
So back in early 2019 we were all stuck, even that Arab guru, Jaafar Tribak
Now, this is the interesting thing, consider from back then in 2019, one of Jaafar Tribak’s / ("my" version of his) failed ( failed in Office 2016 ) attempts, ( and I will call this and similar looking ones from now on the small coding to distinguish it from the big ones that we had all back then been looking at and which had become the standard one used by many people for a long time)
( Note also, that back then, we all seem to have all missed the fact that this small one does actually work in Offices 2003, 2007, 2010, 2013. So we had an alternative coding to the big ones most people had been using, but we all missed that, because we were concentrating on getting something to work in Office 2016 )
This is that smaller coding that we missed and would be an alternative to the previously widely used bigger type of codings, (with a few simple mods from me to help in the following comparisons in discussions)
Code:
Option Explicit
#If 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
#Else
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
#End If
Sub small_2019_ClearOfficeClipBoard() ' Slightly modified attempt of Jaafar Tribak from 2019 to do the Clear All button https://www.mrexcel.com/board/threads/reset-clear-clipboard.1087948/#post-5228633 https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues/page11#post17966
Dim avAcc, bClipboard As Boolean, j As Long
Dim MyPain As String
If CLng(Val(Application.Version)) <= 11 Then ' Case 11: "Excel 2003" Windows "Excel 2004"
Let MyPain = "Task Pane"
Else
Let MyPain = "Office Clipboard"
End If
Set avAcc = Application.CommandBars(MyPain) '
Let bClipboard = avAcc.Visible
If Not bClipboard Then
Let avAcc.Visible = True
DoEvents
End If
For j = 1 To 4 ' J= 1, 2, 3, 4
AccessibleChildren avAcc, Choose(j, 0, 3, 0, 3), 1, avAcc, 1
Next
avAcc.accDoDefaultAction 2& ' This seems to do the clearing 1& for paste
Let Application.CommandBars(MyPain).Visible = bClipboard '
End Sub
You can see straight away that it has strong similarity to what Hans found , (which stems from a post at stack overflow from late 2020 ).
Bookmarks