• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Clear the Office Clipboard ! "E v R" excellent code.

Status
Niet open voor verdere reacties.
Anyway, I'll keep exploring the inspect spy tool and see if I can get to the bottom of this. (BTW, I am new to inspect spy tool and I think it is an excellent helping tool)

:thumb: Please share your findings!
 
Nog 1 stapje erbij in het loopje:
Code:
Public Sub ClearOfficeClipBoard4()
    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
 
@alpha

Ik bedoelde: lijkt nogal overbodig als die geen andere waarde dan 0 krijgt. Dan kan die 0 net zo goed meteen ingevoerd worden.

@ E v R

?

Code:
avAcc.Visible = bClipboard
 
Laatst bewerkt:
avAcc.Visible = bClipboard lukt niet meer aan het einde ;)
 
@snb
De waarde lcount is altijd 1, maar ik snap je idee.
 
Laatst bewerkt:
@E v R

Of course, het ging me na minuten dagen.
 
@RAFAAJ200
Download "accexplorer 2.0", with this tool i can show you how EvR gets his/her index numbers.

For some reason inspect.exe (v7.0.0.0) and inspect32.exe don't show me a tree :(
 
Laatst bewerkt:
@alpha, ook ik ben benieuwd;)
Ik heb ze iig door de code te volgen

Vind dit overigens wel een leuk draadje; heb zo'n 10 excel/vba helden/heldinnen..
3 daarvan reageren meerdere keren in dit draadje
 
I think that explore.exe, explore32.exe, UIspy.exe are not showing the whole tree structure for this problem, so i used "accexplorer 2.0"

Each element has an different "role"
Some elements are "windows", some elements are "clients", "menu bars", "title bars", "buttons" and "property pages"
You need all these elements to find the right indexes.
explore.exe, explore32.exe, UIspy.exe are only showing windows, so you can't relate the indexes

AccessibleChildren has an index starting at 0
.accChild and .accDoDefaultAction have an index starting at 1
accexplorer clipboard 1.gif
Needles to say that you can only choose "visible" elements.

@all
Do you know another example of something which can't be done in VBA-code, but is possible by the excel-menu-structure.
So i can test my theory, Thanks
 
Laatst bewerkt:
E.g.

'screenclipping' ?
adding/removing controls to the QAT.
remove an addin from the addin list
 
Laatst bewerkt:
ANd then to polish things a bit more, ensure this is 64 bit Office compliant:
Code:
#If VBA7 Then
    Private 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
    Private 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
 
After further exploring this subject, and based on code posted here, this is my modest contribution :

I have written 3 convinient functions :

1-IsOfficeClipboardEmpty : Bool that returns if the office clipboard is empty or not.
2-OfficeClipboardElementsCount : Returns number of elements on the office clipboard if any.
3-TextFromOfficeClipboardItem : Takes an item index and returns the text displayed by the clipboard element with that index.

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

Const CHILDID_SELF = &H0&
Const NAVDIR_FIRSTCHILD = &H7&
Const NAVDIR_LASTCHILD = &H8
Const NAVDIR_DOWN = &H2
 

Function IsOfficeClipboardEmpty() As Boolean
    Dim vAcc As Variant, bClipbord As Boolean, i As Long
        
    With Application.CommandBars("Office Clipboard")
        bClipbord = .Visible
        .Visible = True
        DoEvents
        Set vAcc = Application.CommandBars("Office Clipboard")
        For i = 1 To 5
            AccessibleChildren vAcc, Choose(i, 0, 3, 0, 3, 4), 1, vAcc, 1
        Next
        .Visible = bClipbord
    End With
    IsOfficeClipboardEmpty = Not CBool(vAcc.accState(vAcc.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF)))
End Function

Function OfficeClipboardElementsCount() As Long
    Dim vAcc As Variant, i As Long, lLastChildIndex As Long, lFirstChildIndex As Long, bClipbord As Boolean

    With Application.CommandBars("Office Clipboard")
        bClipbord = .Visible
        .Visible = True
        DoEvents
        Set vAcc = Application.CommandBars("Office Clipboard")
        For i = 1 To 5
            AccessibleChildren vAcc, Choose(i, 0, 3, 0, 3, 4), 1, vAcc, 1
        Next
        .Visible = bClipbord
    End With
    lFirstChildIndex = vAcc.accState(vAcc.accNavigate(NAVDIR_FIRSTCHILD, CHILDID_SELF))
    lLastChildIndex = vAcc.accNavigate(NAVDIR_LASTCHILD, CHILDID_SELF)
    OfficeClipboardElementsCount = IIf(lFirstChildIndex = 0, 0, lLastChildIndex)
End Function

Function TextFromOfficeClipboardItem(ByVal ItemIndex As Long) As String
    Dim vAcc As Variant, vChildID As Variant, i As Long, bClipbord As Boolean

    With Application.CommandBars("Office Clipboard")
        bClipbord = .Visible
        .Visible = True
        DoEvents
        Set vAcc = Application.CommandBars("Office Clipboard")
        For i = 1 To 5
            AccessibleChildren vAcc, Choose(i, 0, 3, 0, 3, 4), 1, vAcc, 1
        Next
        .Visible = bClipbord
    End With
    With vAcc
        If ItemIndex > 0 Then
            If .accState(CLng(1)) <> 0& And .accChildCount >= ItemIndex Then
                vChildID = CLng(1)
                For i = 1 To ItemIndex - 1
                    vChildID = .accNavigate(NAVDIR_DOWN, CLng(i))
                Next
                TextFromOfficeClipboardItem = .accName(vChildID)
            End If
        End If
    End With
End Function

Test :
Code:
Sub ExampleTest()
    MsgBox IsOfficeClipboardEmpty
    MsgBox OfficeClipboardElementsCount
    MsgBox TextFromOfficeClipboardItem(ItemIndex:=2) '<== Returns text of the 2nd clipboard item
End Sub

Any improvements welcome.
 
Laatst bewerkt:
@RAFAAJ200
Download "accexplorer 2.0", with this tool i can show you how EvR gets his/her index numbers.

For some reason inspect.exe (v7.0.0.0) and inspect32.exe don't show me a tree :(

I have searched all over but I can't find a dwonload site for "accexploer 2.0" .. Can you please point me to a valid download link .. I hope the program is 64bit compatible too.

Thanks.
 
@Alphamax, handig tooltje!
@RAFAAJ200, I like TextFromOfficeClipboardItem
@snb, remove an addin from the addin list, weet jij hoe en of je dat lijstje via vba op het scherm kan krijgen? zoals bijv Application.CommandBars.ExecuteMso ("MacroSecurity")
 
@alphamax,

Thank you very much for the working link... Strangely enough, accexplorer.exe was not included in my windows kit folder - I only had accevent.exe and inspect.exe.

accexplorer shows all the invisible accessibility objects which is great and removes the confusion I had about the unmatching object indexes showed in inspect.exe which is actually what propmpted me to start this thread in the first place.

So thanks again for your help and thanks to all other members who have contributed to this thread.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan