Page 11 of 56 FirstFirst ... 91011121321 ... LastLast
Results 101 to 110 of 554

Thread: Tests Copying pasting Cliipboard issues. and otes on API stuff

  1. #101
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10

    Things related to API - Jaafar Tribak - Clipboard stuff

    Things related to API - Jaafar Tribak - Clipboard stuff
    This is post #101https://www.excelfox.com/forum/showt...ll=1#post17966
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues?p=17966&viewfull=1#post17966
    https://www.excelfox.com/forum/showt...ge11#post17966
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues/page11#post17966




    Repairing and Gleaning some information from here
    https://www.mrexcel.com/board/thread...board.1087948/


    Yasser tried to get some help from us at eileenslounge.com in 2019 to get VBA to do like clicking that Clear All Button
    We got as far it working in Office versions 2003 2007 2010 ( https://eileenslounge.com/viewtopic....246770#p246770
    https://eileenslounge.com/viewtopic....246838#p246838
    ) , that was all I had at the time.
    Yasser went off to mrexcel.com and got some interesting info from Jaafar Tribak , who tried bit failed still to get it working in Office 2016. (Back then he only had Office versions 2007 2010 and 2013).
    Never the less, there was some interesting stuff there to review, unfortunately that mrexcel thread has got a bit messed up by a forum software update, so I tried to make a repaired summarized copy of it, only pulling out the important bits here - I mean here what I am writing now
    Yassers comments/ posts are the green ones
    Yaz: ………

    , Jaafar Tribak’s suggestions are normal black
    Jaf: ………
    , and any new comments or minor modifications from me, based on me trying some of Jaafar Tribak’s suggestions or other more recent experiments are in purple
    Alan 2024: …..






    Jaf: Trys this (This seems to be the first occurrence of what I will call the small one )
    Code:
         ' new small one first occurrance we missed in 2019 at mrexcel    https://www.mrexcel.com/board/threads/reset-clear-clipboard.1087948/#post-5228633
    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()
        Dim avAcc, bClipboard As Boolean, j As Long
    Dim MyPain As String 'COMsOLEwollupsActivelyEmmbeddedXratedObjectHookMyBoutonOhFolloks
        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 )  ' ("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(MyPain ). Visible = bClipboard    '   ("Office Clipboard").Visible = bClipboard
    End Sub


    Yaz: I have tested the code and I got the Clipboard window open then I got Invalid procedure call (Error '5') at this line

    avAcc.accDoDefaultAction 2& '1& for paste


    Alan 2024: Works Office 2007 2010 2013
    For 2003 to work added the MyPain stuff
    (We all seem to have missed this in 2019, this new
    small one, which would appear for versions 2013 and lower to work as well as the big ones

    For Office 2016, same as Yasser, Runtime error '5'
    Ungültiger Prozeduraufruf oder ungültiges Argument
    , and his other finding too


    Jaf: 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&

    Yaz: 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)
    Last edited by DocAElstein; 10-28-2024 at 02:36 PM.

  2. #102
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    dnvdsm
    Last edited by DocAElstein; 10-04-2024 at 11:23 PM.

  3. #103
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    The last post, #102 won't edit Okt 2024



    This is post #103 https://www.excelfox.com/forum/showt...ll=1#post17968
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues?p=17968&viewfull=1#post17968
    https://www.excelfox.com/forum/showt...ge11#post17968
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues/page11#post17968


    Jaf: : Can you run this and tell us the output you get in the immediate window :

    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 ClearOfficeClipBoard()
        Dim avAcc, bClipboard As Boolean, j As Long
    Dim MyPain As String 'COMsOLEwollupsActivelyEmmbeddedXratedObjectHookMyBoutonOhFolloks
        If CLng(Val(Application.Version)) <= 11 Then  '  Case 11: "Excel 2003" Windows     "Excel 2004" mac
         Let MyPain = "Task Pane"
        Else
         Let MyPain = "Office Clipboard"
        End If
    
        Set avAcc = Application.CommandBars(MyPain)
            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(MyPain).Visible = bClipboard
    End Sub
    Yaz: I have changed 2& to 0& to avoid error then I got 0 at the immediate window and then another error at this part
    a.accName(i)
    In valid procedure call or argument


    Jaf: Can you place an On Error Resume Next statement right before :
    Set a = avAcc

    Yaz: I just got 0 in the immediate window
    And I put the line before the line of
    avAcc.accDoDefaultAction 2&
    and I got also 0


    Alan 2024
    2003 (German)
    0 Zusammenstellen und Einfügen 2.0
    1 Alle einfügen
    2 Alle löschen
    3 Klicken Sie zum Einfügen auf ein Element:
    4 Zwischenablage
    5 Zwischenablage
    6 Um diesen Aufgabenbereich später einzublenden, wählen Sie Office-Zwischenablage aus dem Menü Bearbeiten oder drücken Sie Strg+C zwei mal.
    7 Optionen

    2007 (English)
    0 Collect and Paste 2.0
    1 Paste All
    2 Clear All
    3 Click an item to paste:
    4 Clipboard
    5 Clipboard
    6 Options

    2010 2013 (German) ( KB 32 Bit Office 2010 ' 64 Bit windows Office 2010 Veranda Office 2013 SerSzuD2)
    0 Zusammenstellen und Einfügen 2.0
    1 Alle Einfügen
    '2 Alle löschen
    3 Klicken Sie zum Einfügen auf ein Element:
    4 Zwischenablage
    5 Zwischenablage
    6 Optionen



    All other results as Yasser


    Jaf: I don't know why it doesn't work in office 2016. Maybe the hierarchy of the Accessibility buttons is different from that of previous office editions --- unfortunately, I don't use excel 2016 so I could test it.
    Last edited by DocAElstein; 10-28-2024 at 02:39 PM.

  4. #104
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    This is post 104https://www.excelfox.com/forum/showt...ll=1#post17969
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues?p=17969&viewfull=1#post17969
    https://www.excelfox.com/forum/showt...ge11#post17969
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues/page11#post17969



    Jaf: Can you try this other code :

    Code:
    '   https://www.mrexcel.com/board/threads/reset-clear-clipboard.1087948/page-2#post-5228787
    '   Can you try this other code :
    Option Explicit
    
    Private Type POINTAPI
      x As Long
      Y As Long
    End Type
    
    Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
        #If VBA7 Then
        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
        Declare PtrSafe Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As LongPtr, ByVal wFlag As Long) As LongPtr
        Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
        Declare PtrSafe Function BringWindowToTop Lib "user32" (ByVal hwnd As LongPtr) As Long
        Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As LongPtr)
            #If Win64 Then
            Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal arg1 As LongPtr, ppacc As Any, pvarChild As Variant) As Long
            #Else
            Private Declare PtrSafe Function AccessibleObjectFromPoint Lib "oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
            #End If
        Dim hwndClip As LongPtr
        Dim hwndScrollBar As LongPtr
        Dim lngPtr As LongPtr
        #Else
        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
        Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
        Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
        Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
        Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
        Declare Function AccessibleObjectFromPoint Lib "Oleacc" (ByVal lX As Long, ByVal lY As Long, ppacc As IAccessible, pvarChild As Variant) As Long
        Dim hwndClip As Long
        Dim hwndScrollBar As Long
        #End If
    
    
    Const GW_CHILD = 5
    Const S_OK = 0
    
    
    Sub big_ClearOfficeClipBoard()
    
        Dim tRect1 As RECT, tRect2 As RECT
        Dim tPt As POINTAPI
        Dim oIA As IAccessible
        Dim vKid  As Variant
        Dim lResult As Long
        Dim i As Long
        Static bHidden As Boolean
          
        If CommandBars("Office Clipboard").Visible = False Then
            bHidden = True
            CommandBars("Office Clipboard").Visible = True
            Application.OnTime Now, "ClearOfficeClipBoard": Exit Sub
        End If
    
    
        hwndClip = FindWindowEx(Application.hwnd, 0, "EXCEL2", vbNullString)
        hwndClip = FindWindowEx(hwndClip, 0, "MsoCommandBar", CommandBars("Office Clipboard").NameLocal)
        hwndClip = GetNextWindow(hwndClip, GW_CHILD)
        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)
                lResult = AccessibleObjectFromPoint(lngPtr, oIA, vKid)
                #Else
                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): CommandBars("Office Clipboard").Visible = Not bHidden: bHidden = False: Exit Sub
                End If
                DoEvents
            Next i
        End If
        CommandBars("Office Clipboard").Visible = Not bHidden
        MsgBox "Unable to clear the Office Clipboard"
    
    End Sub
    
    If the above doesn't work for you either, can you tell me if you get an error and on which line ?


    Yaz: I got an error "Object doesn't support this property or method 'Error 438' "
    at this line
    Call oIA.accDoDefaultAction(vKid)


    Alan 2024: This coding appeared very similar to my final offering in 2019. To make a better comparison I have made changes, mostly in coding layout in the coding above, and in an updated version of "mine"** With those changes, they are almost identical .
    My findings have been discussed already, (
    )
    I had similar findings to Yasser, - the problem seemed to be that we could not get it to work in Office 2016


    Jaf: Try adding a MsgBox to the code :
    Code:
                If InStr("Clear All - Borrar todo - Effacer tout", oIA.accName(vKid)) Then
                   MsgBox vKid
                    Call oIA.accDoDefaultAction(vKid): CommandBars("Office Clipboard").Visible = Not bHidden: bHidden = False: Exit Sub
                End If
    What value does the MsgBox show ?

    Yaz: The value of vKid is 0

    Jaf: I am afraid, I don't have excel 2016 for testing -- The two codes I have posted work fine in excel 2007 , 2010 and 2013
    Last edited by DocAElstein; 10-28-2024 at 02:15 PM.

  5. #105
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    This is post #105 https://www.excelfox.com/forum/showt...ll=1#post17970
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues?p=17970&viewfull=1#post17970
    https://www.excelfox.com/forum/showt...ge11#post17970
    https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-pasting-Cliipboard-issues/page11#post17970




    https://www.mrexcel.com/board/thread...2#post-5228992
    Yaz: Is there a way or steps that I can do for you so as to clarify the issue for excel 2016 .. such as using specific program that shows the APIs of the "Clear All" button for this version?


    Jaf: I don't think it is going to be possible for me to find out where the problem lies without me having a copy of office 2016 for testing.
    I guess the reason for the code not working in office 2016 is that the hierarchy of the accessible buttons in the office clipboard has changed.

    Yaz: ….( Arabisch – erkannt ) … Is it possible to use TeamViewer so that you can see the problem from my device?? Or is it possible for me to walk with you through the steps in any program so that you can see the structure of version 2016??

    Jaf: I am afraid that is not going to be possible as I have no idea about remote stuff.

    If I get hold of a computer that has office 2016 installed in it, I will definitely let you know.
    Last edited by DocAElstein; 10-28-2024 at 02:44 PM.

  6. #106
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    sddljjldsk
    Last edited by DocAElstein; 10-04-2024 at 11:26 PM.

  7. #107
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    kvjdshv
    Last edited by DocAElstein; 10-04-2024 at 11:27 PM.

  8. #108
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    dslkjvsdj
    Last edited by DocAElstein; 10-04-2024 at 11:27 PM.

  9. #109
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    x,v,
    Last edited by DocAElstein; 10-04-2024 at 11:28 PM.

  10. #110
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,458
    Rep Power
    10
    Last edited by DocAElstein; 10-07-2024 at 01:36 PM.

Similar Threads

  1. Replies: 114
    Last Post: 03-04-2024, 02:39 PM
  2. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  3. Replies: 11
    Last Post: 10-13-2013, 10:53 PM
  4. Replies: 7
    Last Post: 08-28-2013, 12:57 AM
  5. Declaring API Functions In 64 Bit
    By marreco in forum Excel Help
    Replies: 2
    Last Post: 02-11-2013, 03:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •