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.
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
Comment