Modeless VBA UserForm after switch from MDI to SDI RRS feed

  • General discussion

  • After searching around for a solution for the problem of having Modeless UserForms on top of all opened WorkBooks after switching form office14 to office15 (2013) I had came for this bit of workaround to try to solve the problem

    Firstly you have to use some of the API Functions as follows on the top of the 'ThisWorkBook' Module with all workbooks which you want to have your userform to stay at top of them when switching between them:

    Private Declare Function FindWindow Lib "user32" _
                                        Alias "FindWindowA" ( _
                                        ByVal lpClassName As String, _
                                        ByVal lpWindowName As String) As Long
    Private Declare Function SetParent Lib "user32" ( _
                                       ByVal hWndChild As Long, _
                                       ByVal hWndNewParent As Long) As Long
    Private Declare Function BringWindowToTop Lib "user32" ( _
                                       ByVal HWnd As Long) As Long
    *Please remember that you must add the previous code at the very top of  'ThisWorkBook' module and before anything else

    Then add the following code to the WindowActivate Event, it would appear like below:

    Private Sub Workbook_WindowActivate(ByVal Wn As Window)
    If Val(Application.Version) >= 15 Then BringWindowToTop (FindWindow("ThunderDFrame", "YOUR USERFORM CAPTION"))
    End Sub

    That solved the problem for me, I hope it would be helpful for you too


    • Moved by Quist Zhang Wednesday, February 20, 2013 9:27 AM
    Tuesday, February 19, 2013 7:30 PM

All replies