The last post inspired me a bit to take another look at this snippet.
I did some modifications to help take a closer lookCode:Let hwndClip = FindWindowEx(Application.hWnd, 0, "EXCEL2", vbNullString) Let hwndClip = FindWindowEx(hwndClip, 0, "MsoCommandBar", CommandBars(MyPain).NameLocal) Let hwndClip = GetNextWindow(hwndClip, GW_CHILD) Let hwndScrollBar = GetNextWindow(GetNextWindow(hwndClip, GW_CHILD), GW_CHILD) If hwndClip And hwndScrollBar Then GetWindowRect hwndClip, tRect1 GetWindowRect hwndScrollBar, tRect2 BringWindowToTop Application.hWnd For i = 0 To tRect1.Right - tRect1.Left Step 50 tPt.x = tRect1.Left + i: tPt.Y = tRect1.Top - 10 + (tRect2.Top - tRect1.Top) / 2 #If VBA7 And Win64 Then CopyMemory lngPtr, tPt, LenB(tPt) Let lResult = AccessibleObjectFromPoint(lngPtr, oIA, vKid) #Else Let lResult = AccessibleObjectFromPoint(tPt.x, tPt.Y, oIA, vKid) #End If ' If InStr("Clear All Borrar todo Effacer tout Alle löschen La légende du bouton", oIA.accName(vKid)) Then Call oIA.accDoDefaultAction(vKid) ' This does the clearing, and CommandBars(MyPain).Visible = Not bHidden ' Let bHidden = False Exit Sub End If DoEvents Next i End If
(The modifications are
_ 1) a small change to prevent the code erroring if finds a button or something without any caption
_2) some Debug.Print lines )
Here is the modified versionCode:' 1180958 Let hwndClip = FindWindowEx(Application.hwnd, 0, "EXCEL2", vbNullString): Debug.Print "hwndClip " & hwndClip Let hwndClip = FindWindowEx(hwndClip, 0, "MsoCommandBar", CommandBars(MyPain).NameLocal): Debug.Print "hwndClip " & hwndClip ' 591464 Let hwndClip = GetNextWindow(hwndClip, GW_CHILD): Debug.Print "hwndClip " & hwndClip ' 721906 Let hwndScrollBar = GetNextWindow(GetNextWindow(hwndClip, GW_CHILD), GW_CHILD): Debug.Print "hwndScrollBar " & hwndScrollBar ' 787440 Debug.Print If hwndClip And hwndScrollBar Then GetWindowRect hwndClip, tRect1 GetWindowRect hwndScrollBar, tRect2 BringWindowToTop Application.hwnd Debug.Print " tRect1.Top = " & tRect1.Top & " tRect2.Top = " & tRect2.Top Debug.Print "( tRect1.Bottom = " & tRect1.Bottom & " tRect2.Bottom = " & tRect2.Bottom & " )" Debug.Print "Loop i from 0 To (" & tRect1.Right & "-" & tRect1.Left & ")=" & tRect1.Right - tRect1.Left & " Step 50" For i = 0 To tRect1.Right - tRect1.Left Step 50 Let tPt.x = tRect1.Left + i Let tPt.Y = tRect1.Top - 10 + (tRect2.Top - tRect1.Top) / 2: Debug.Print "i=" & Format(i, "000") & " tPt.x = " & tPt.x & " tPt.Y = " & tPt.Y #If VBA7 And Win64 Then CopyMemory lngPtr, tPt, LenB(tPt) Let lResult = AccessibleObjectFromPoint(lngPtr, oIA, vKid) #Else Let lResult = AccessibleObjectFromPoint(tPt.x, tPt.Y, oIA, vKid) #End If ' Debug.Print "lResult " & lResult & " vKid " & vKid & " oIA.accName(vKid) """ & oIA.accName(vKid) & """" If oIA.accName(vKid) <> "" And InStr("Clear All Borrar todo Effacer tout Alle löschen La légende du bouton", oIA.accName(vKid)) > 0 Then Call oIA.accDoDefaultAction(vKid) ' This does the clearing, and CommandBars(MyPain).Visible = Not bHidden ' Let bHidden = False Debug.Print "Worked, :-)" Stop: Exit Sub End If DoEvents Next i End If Let CommandBars(MyPain).Visible = Not bHidden Debug.Print "Unable to clear the Office Clipboard, didn't work, :-(" Stop End Sub
Results in the next two posts
https://www.excelfox.com/forum/showt...ll=1#post18042
https://www.excelfox.com/forum/showt...ll=1#post18043




Reply With Quote
Bookmarks