Advertisement
AlanElston

Clear Office Clipboard

Feb 19th, 2019
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Rory http://www.eileenslounge.com/viewtopic.php?f=30&t=31849&p=246770#p246770
  2. ' Don un CK76 https://www.excelforum.com/excel-programming-vba-macros/1217178-clipboard-not-clearing-application-cutcopymode-false.html
  3. ' Jaafar Tribak https://www.mrexcel.com/forum/excel-questions/1087948-reset-clear-clipboard-2.html
  4. ' Rory https://excelribbon.tips.net/T008938_Determining_Your_Version_of_Excel.html
  5. ' Jack's 'COMsOLEwollupsActivelyEmmbeddedXratedObjectHookMyBouton version ' https://www.youtube.com/watch?v=jY-PEeX5xYY&t=2s
  6. ' FOR NON ENGLISH EXCEL avec moi si vou ple La légende du bouton ' ##### http://www.eileenslounge.com/viewtopic.php?f=30&t=31849&p=246770#p246770
  7. Option Explicit '
  8. Private Type POINTAPI
  9.  x As Long: Y As Long
  10. End Type
  11. Type RECT
  12.  Left As Long
  13.  Top As Long
  14.  Right As Long
  15.  Bottom As Long
  16. End Type
  17.     #If VBA7 Then
  18.     Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr
  19.     Declare PtrSafe Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As LongPtr, ByVal wFlag As Long) As LongPtr
  20.     Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
  21.     Declare PtrSafe Function BringWindowToTop Lib "user32" (ByVal hwnd As LongPtr) As Long
  22.     Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
  23.         #If Win64 Then
  24.         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
  25.         #Else
  26.         Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
  27.         #End If
  28.     Dim hwndClip As LongPtr
  29.     Dim hwndScrollBar As LongPtr
  30.     Dim lngPtr As LongPtr
  31.     #Else
  32.     Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  33.     Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wFlag As Long) As Long
  34.     Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
  35.     Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long
  36.     Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  37.     Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
  38.     Dim hwndClip As Long
  39.     Dim hwndScrollBar As Long
  40.     #End If
  41. Const GW_CHILD = 5
  42. Const S_OK = 0
  43.  
  44. Sub ClearOffPainBouton() 'OhFolloks
  45. 'Application.DisplayClipboardWindow = True
  46. Dim tRect1 As RECT, tRect2 As RECT
  47. Dim tPt As POINTAPI
  48. Dim oIA As IAccessible
  49. Dim vKid  As Variant
  50. Dim lResult As Long
  51. Dim i As Long
  52. Static bHidden As Boolean
  53. Dim MyPain As String 'COMsOLEwollupsActivelyEmmbeddedXratedObjectHookMyBoutonOhFolloks
  54.    If CLng(Val(Application.Version)) <= 11 Then
  55.      Let MyPain = "Task Pane"
  56.     Else
  57.      Let MyPain = "Office Clipboard"
  58.     End If
  59.     If CommandBars(MyPain).Visible = False Then
  60.      bHidden = True
  61.      CommandBars(MyPain).Visible = True
  62.      Application.OnTime Now, "ClearOffPainBouton": Exit Sub
  63.     End If
  64.  
  65. Let hwndClip = FindWindowEx(Application.hWnd, 0, "EXCEL2", vbNullString)
  66. Let hwndClip = FindWindowEx(hwndClip, 0, "MsoCommandBar", CommandBars(MyPain).NameLocal)
  67. Let hwndClip = GetNextWindow(hwndClip, GW_CHILD)
  68. Let hwndScrollBar = GetNextWindow(GetNextWindow(hwndClip, GW_CHILD), GW_CHILD)
  69.    
  70.     If hwndClip And hwndScrollBar Then
  71.      GetWindowRect hwndClip, tRect1
  72.      GetWindowRect hwndScrollBar, tRect2
  73.      BringWindowToTop Application.hWnd
  74.         For i = 0 To tRect1.Right - tRect1.Left Step 50
  75.          tPt.x = tRect1.Left + i: tPt.Y = tRect1.Top - 10 + (tRect2.Top - tRect1.Top) / 2
  76.             #If VBA7 And Win64 Then
  77.              CopyMemory lngPtr, tPt, LenB(tPt)
  78.              Let lResult = AccessibleObjectFromPoint(lngPtr, oIA, vKid)
  79.             #Else
  80.              Let lResult = AccessibleObjectFromPoint(tPt.x, tPt.Y, oIA, vKid)
  81.             #End If ' ##### avec moi si vou ple La légende du bouton
  82.            If InStr("Clear All Borrar todo Effacer tout Alle löschen La légende du bouton", oIA.accName(vKid)) Then
  83.              Call oIA.accDoDefaultAction(vKid): CommandBars(MyPain).Visible = Not bHidden: bHidden = False: Exit Sub
  84.             End If
  85.          DoEvents
  86.         Next i
  87.     End If
  88.  Let CommandBars(MyPain).Visible = Not bHidden
  89.  MsgBox "Unable to clear the Office Clipboard"
  90. End Sub
  91.  
  92. Sub TestVersion() ' Rory Archibald 2015
  93. MsgBox Prompt:=ExcelVersion
  94.  MsgBox Prompt:=CLng(Val(Application.Version))
  95. End Sub
  96. Private Function ExcelVersion() As String
  97.     Dim temp                  As String
  98.  
  99.     'On Error Resume Next
  100. #If Mac Then
  101.     Select Case CLng(Val(Application.Version))
  102.         Case 11: temp = "Excel 2004"
  103.         Case 12: temp = "Excel 2008" ' this should NEVER happen!
  104.        Case 14: temp = "Excel 2011"
  105.         Case 15: temp = "Excel 2016 (Mac)"
  106.         Case Else: temp = "Unknown"
  107.     End Select
  108. #Else
  109.     Select Case CLng(Val(Application.Version))
  110.         Case 9: temp = "Excel 2000"
  111.         Case 10: temp = "Excel 2002"
  112.         Case 11: temp = "Excel 2003"
  113.         Case 12: temp = "Excel 2007"
  114.         Case 14: temp = "Excel 2010"
  115.         Case 15: temp = "Excel 2013"
  116.         Case 16: temp = "Excel 2016 (Windows)"
  117.         Case Else: temp = "Unknown"
  118.     End Select
  119. #End If
  120. #If Win64 Then
  121.     temp = temp & " 64 bit"
  122. #Else
  123.     temp = temp & " 32 bit"
  124. #End If
  125.  
  126.     ExcelVersion = temp
  127. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement