TypeOf Operator - IAccessible Interface implementation

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,596
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

As you know, the TypeOf operator cheks if an object implements a certain interface so the following 2 codes return TRUE as expected :

in a userform module:
Code:
Private Sub UserForm_Click()
    MsgBox TypeOf Me Is IAccessible
End Sub

The same goes for this :
Code:
Private Sub Test1()
    MsgBox TypeOf Application.CommandBars(1) Is IAccessible
End Sub

However when we apply this to the Application object, the return is False despite the fact that the Application object does also implement the IAccessible interface !
Code:
Private Sub Test2()
    MsgBox TypeOf Application Is IAccessible
End Sub

Any ideas why this is the case ?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Are you sure it does implement it? Accessibleobjectfromwindow never returns an Application object directly that I’ve seen.
 
Upvote 0
Are you sure it does implement it? Accessibleobjectfromwindow never returns an Application object directly that I’ve seen.

Yes it does .. Accessible browser tools like AccExploer.exe and others work on the application object and return the corresponding accessible elements.
 
Upvote 0
You can verify this by trying some vba code like this :
Rich (BB code):
Option Explicit

Type GUID
    lData1 As Long
    iData2 As Integer
    iData3 As Integer
    iData4(0 To 7) As Byte
End Type

#If  VBA7 Then
    Declare PtrSafe Function AccessibleObjectFromWindow Lib "OLEACC.DLL" (ByVal hwnd As LongPtr, ByVal dwId As Long, ByVal riid As LongPtr, ppvObject As Any) As Long
    Declare PtrSafe Function IIDFromString Lib "ole32.dll" (ByVal lpsz As LongPtr, ByVal lpiid As LongPtr) As LongPtr
#Else
    Declare Function AccessibleObjectFromWindow Lib "OLEACC.DLL" (ByVal hwnd As Long, ByVal dwId As Long, ByVal riid As Long, ppvObject As Any) As Long
    Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByVal lpiid As Long) As Long
#End  If

Const S_OK = &H0
Const OBJID_SELF = &H0&
Const CHILDID_SELF = &H0&

Sub Test()
    Const ID_ACCESSIBLE As String = "{618736E0-3C3D-11CF-810C-00AA00389B71}"
    Dim tGUID(0 To 3) As Long
    Dim oIAc As IAccessible
   
    If IIDFromString(StrPtr(ID_ACCESSIBLE), VarPtr(tGUID(0))) = S_OK Then
        If AccessibleObjectFromWindow(Application.hwnd, OBJID_SELF, VarPtr(tGUID(0)), oIAc) = S_OK Then
            'return the application caption.
            MsgBox oIAc.accName(CHILDID_SELF) ' <=== Excel.Application class implements IAccessible
        End If
    End If
End Sub
 
Last edited by a moderator:
Upvote 0
I can only guess maybe there's some other intermediate layer there. The object browser certainly doesn't list any of the IAccessible methods for Application but perhaps it is possible that the interface is somehow not COM exposed?
 
Upvote 0
I can only guess maybe there's some other intermediate layer there. The object browser certainly doesn't list any of the IAccessible methods for Application but perhaps it is possible that the interface is somehow not COM exposed?

Maybe.. but then again the classes in the Msforms library don't expose any IAccessible methods either yet, the TypeOf operator returns True !... I must be missing something... I've looked on the internet but couldn't find any info on the subject.

Regards.
 
Upvote 0
Looking through the Object Browser, I can only see IAccessible methods for objects in the Office or Access libraries, so it looks like the they aren't exposed to COM. I know they did some work recently on accessibiity and forms but I couldn't tell you why TypeOf works for a userform and not for Application. I'll be pleasantly surprised if anyone outside of MS can.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top