Can anyone test this code for me (IAccessibility)

Jaafar Tribak

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

Not sure if this is the right section of the forum to ask this question but I am trying to get the accessibility names of the workbook scrollbars and tabs .. The AccName function returns a string that is language dependent so when I run the code on my machine, I get the AccName in French. (I am using the french version of office)

As part of a small project I am working on, I need to know the English equivalent.

Can anyone please tell me what the exact strings they get in the immediate window after running the Test Macro ?

Regards.


In a Standard Module:
Code:
Option Explicit

[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL]  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 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
    Declare PtrSafe Function IIDFromString Lib "ole32.dll" (ByVal lpsz As LongPtr, ByVal lpiid As LongPtr) As LongPtr
    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
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL] 
    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 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
    Declare Function IIDFromString Lib "ole32.dll" (ByVal lpsz As Long, ByVal lpiid As Long) As Long
    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
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL]  If


Const S_OK = &H0
Const OBJID_SELF = &H0&
Const CHILDID_SELF = &H0&
Const ID_ACCESSIBLE As String = "{618736E0-3C3D-11CF-810C-00AA00389B71}"



Sub Test()

    Dim tGUID(0 To 3) As Long
    Dim oIAc As IAccessible
    Dim vAcc As Variant, vAccChild As Variant
    Dim i As Long
    Dim bVerScroll As Boolean, bHorScroll As Boolean, bTabs As Boolean
    
    On Error GoTo errHandler
    
    With ThisWorkbook.Windows(1)
        bVerScroll = .DisplayVerticalScrollBar
        bHorScroll = .DisplayHorizontalScrollBar
        bTabs = .DisplayWorkbookTabs
        .DisplayVerticalScrollBar = True
        .DisplayHorizontalScrollBar = True
        .DisplayWorkbookTabs = True
    End With

    If IIDFromString(StrPtr(ID_ACCESSIBLE), VarPtr(tGUID(0))) = S_OK Then
        If AccessibleObjectFromWindow(FindWindowEx(FindWindowEx(Application.hwnd, 0, "XLDESK", vbNullString), 0, "EXCEL7", vbNullString), OBJID_SELF, VarPtr(tGUID(0)), oIAc) = S_OK Then
            Set vAcc = oIAc
            AccessibleChildren vAcc, 3, 1, vAcc, 1
            For i = 0 To oIAc.accChildCount - 1
                AccessibleChildren vAcc, i, 1, vAccChild, 1
                Debug.Print vAccChild.accName(CHILDID_SELF)
            Next i
        End If
    End If
    
errHandler:

    With ThisWorkbook.Windows(1)
        .DisplayVerticalScrollBar = bVerScroll
        .DisplayHorizontalScrollBar = bHorScroll
         .DisplayWorkbookTabs = bTabs
    End With

End Sub
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I have a new related request as I need to confirm that the window names of the workbook Vertical and Horizontal scrollbars are the same in French and English versions of excel.

Can anybody using an English edition of excel be so kind to test the following code for me and tell me whether they get TRUE or FALSE in the immediate window ?

Also, can you tell me the version of excel you tested the code in ( ie: 2007, 2010 etc)

Thank you.

Code:
Option Explicit

[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]  VBA7 Then
    Declare PtrSafe Function IsWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
    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
    
    Dim hWbk As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] 
    Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
    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
    
    Dim hWbk As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]  If


Sub Test()    

    hWbk = FindWindowEx(FindWindowEx(Application.hwnd, 0, "XLDESK", vbNullString), 0, "EXCEL7", vbNullString)
     
    Debug.Print CBool(IsWindow(FindWindowEx(hWbk, 0, "NUIScrollbar", "Vertical")))
    Debug.Print CBool(IsWindow(FindWindowEx(hWbk, 0, "NUIScrollbar", "Horizontal")))

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,028
Members
452,542
Latest member
Bricklin

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