API Function FindWindowEx works on my PC but not end user

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trompomerson
    New Member
    • Jan 2008
    • 3

    API Function FindWindowEx works on my PC but not end user

    Hello,

    I am running the code below in an Excell '03 userform, the purpose of the code is to set the form as a child of the workbook so it moves around with it etc. however the last call to the FindWindowEx function only works on my PC when run but not on my end-user's. The frustrating part is that the first call to the function runs fine but not the second. Hopefully someone with more experience using API's may have an answer to this since I'm completely stumped. On a side note, another developer in my office is also able to run the code successfully. Would there be a problem with the fact that the end-user's version of the workbook is being opened as Read-Only? Any help would be much appreciated.

    Code:
    Private 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
    
    Private Sub UserForm_Initialize()
    AppHWnd = Application.hwnd
    If AppHWnd > 0 Then
        ' get the window handle of the Excel desktop
        DeskHWnd = FindWindowEx(AppHWnd, 0, "XLDESK", vbNullString)
        If DeskHWnd > 0 Then
            ' get the window handle of the ActiveWindow
            WindowHWnd = FindWindowEx(DeskHWnd, 0, "EXCEL7", ActiveWindow.Caption)
    ...
    End Sub
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by Trompomerson
    Hello,
    (...)
    Would there be a problem with the fact that the end-user's version of the workbook is being opened as Read-Only? Any help would be much appreciated.

    [CODE=vb]
    '(...)
    ' get the window handle of the ActiveWindow
    WindowHWnd = FindWindowEx(De skHWnd, 0, "EXCEL7", ActiveWindow.Ca ption)
    ...
    End Sub
    [/CODE]
    Yes, it's because it's Read-Only:

    When you ask for its name to be ActiveWindow.Ca ption, that'll be the name of the VBA window, that doesn't have the [Read-Only] tag but the Excel application does. If you have no other workbooks open in that excel, you can have the code search for vbnullstring instead.

    HTH

    Comment

    Working...