2

I'm running a PowerPoint Macro-Enabled Slide Show. When a user opens this file the presentation starts immediately. The presentation contains various shapes that, when pressed (use of links), will open a new Powerpoint Slide Show in front of the main Slide Show.

In the background I'm using VBA (code is located in the main Macro enabled slide show) to measure the time a user spends on all of the slides. I want the user to be able to stop this timer with a userform and a button. However, when a new Powerpoint Slide Show is opened, it appears in front of the main slide show. The userform will then disappears behind the new slide show. Using a second screen i have been able to view the userform. But when clicked on the userform it brings the main slide show in front of the other slide show.

So in short: I would like a userform that is in front of all slide show windows.

I tried using vbmodeless but this does not help. I've also tried out various bits of code:

Unfortunately, none of these seem to be working. Some of these are for excel and I've not been able to rewrite these bits of code.

P.S. If this isn't possible, maybe I could hide the main slide show?

Tim
  • 23
  • 3

1 Answers1

1

Simple version
Create a class module, MyClass, and put this code there:

Public WithEvents App As Application
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
    UserForm1.Show False
End Sub

Create a module and put this code in it:

Dim MyThing As New MyClass
Sub InitializeApp()
    Set MyThing.App = Application
End Sub

Run the InitializeApp method first. Now, when you start your presentation, your UserForm1 will show up. The False flag makes it non-modal, which is what I think you are looking for.

Slightly more advanced version
As above, but change the module to this:

Option Explicit

Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1

Public Const HWND_TOP = 0
Public Const HWND_BOTTOM = 1
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Public Declare 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 uFlags As Long) As Long

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


Dim MyThing As New MyClass
Sub InitializeApp()
    Set MyThing.App = Application
End Sub

And add this to your form code:

Option Explicit

Option Explicit

Private Sub UserForm_Initialize()
    Dim formHWnd As Long
    formHWnd = FindWindow("ThunderDFrame", Me.Caption)
    SetWindowPos formHWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
Sam
  • 5,424
  • 1
  • 18
  • 33
  • Thank you! This works like a charm :) As a side note: this only works when you close PowerPoint and start the presentation. When you start the presentation from inside the PowerPoint editor this does not work. – Tim Aug 06 '21 at 09:39
  • I suppose that is your goal. If not, have a look here: https://stackoverflow.com/questions/11306007/how-to-auto-execute-a-macro-when-opening-a-powerpoint-presentation – Sam Aug 06 '21 at 10:34
  • I've played around with your snippets of code and came across an edge case. When I open a sub slideshow from inside the main slideshow everything works fine. I can interact with the form that is in front of the sub slide show. However, when i try to open a slideshow from inside the sub slide show I encounter the same problem as before. When i press the form it forces the sub slide show to appear in front of the new opened sub sub slide show. Do you have any ideas on how to deal with this? – Tim Aug 06 '21 at 12:33