Results 1 to 5 of 5

Thread: How To Bring Userform In Front Of Another Application Other Than Parent Application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0

    How To Bring Userform In Front Of Another Application Other Than Parent Application

    I have created a modeless UserForm in Powerpoint 2013 vba in Windows 8 which displays while the user to perform a certain task in Excel and then press OK.
    When the user switches the program to Excel, the form is hidden behind. I want it to be displayed in front of all opened windows regardless of program type.
    I tried SetWindowsPos but this does not seem to work on Windows 8.
    Is there a way to display the form on top without going through the task of signing up trusted certificate?

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Does the SetWindowsPos give you the desired feature in Win 7 or previous? Don't have a Win 8, so cannot check.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0

    I found the cause

    Quote Originally Posted by Excel Fox View Post
    Does the SetWindowsPos give you the desired feature in Win 7 or previous? Don't have a Win 8, so cannot check.
    Thanks to your remark, I tested further and found the cause. It was not the SetWindowPos, but because I wrongly declared the FindWindow API. Now, it's working fine on Powerpoint 2013-Windows 8.
    But curiously, when I bring this VBA to Powerpoint 2010-Windows 7, I obtain an error message saying the program could not read dll. I'll have to find a way so that it works on both PPT 2010 and 2013 on Windows 7 and 8.

    Thank you again.

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Can you post a trimmed down version of the powerpoint file with the form and vba which works in Win 8. If as you say it's working fine on Win 8, will try to integrate some code to make it compatible for both Win 8 and Win 7.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0
    Thank you for your helpful suggestions. I have since tested with other PCs and found that this problem occurs only on one particular PC. So it must be some error on the side of the PC, not the code itself.

    For reference, here is the script I have written. (This is only the essence. Error handling, etc. are omitted)
    Assuming a UserForm1 is created:

    Public Declare PtrSafe Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1

    Public Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Sub ShowFormOnTop()
    Dim bwind As Long

    Load UserForm1
    UserForm1.Show vbModeless

    If UserForm1.Visible = True Then
    bwind = FindWindow(vbNullString, UserForm1.Caption)
    Else
    bwind = 0
    End If
    SetWindowPos bwind, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End Sub
    ----------------------------
    Thank you again.

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2013, 03:43 PM
  2. Add VBA Reference From Another Application Excel To PowerPoint
    By ds1001 in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 06-02-2013, 02:43 PM
  3. Application.Caller
    By Transformer in forum Familiar with Commands and Formulas
    Replies: 0
    Last Post: 05-01-2013, 12:32 PM
  4. Excel Application.OnKey With Parameter
    By Excel Fox in forum Excel Help
    Replies: 0
    Last Post: 11-29-2011, 01:31 PM
  5. Application.ScreenUpdating = False not working
    By LalitPandey87 in forum Excel Help
    Replies: 2
    Last Post: 11-08-2011, 08:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •