Userform appears behind other application

S

simonc

I am writing a macro which opens a powerpoint file and extracts information
from it into a spreadsheet. I have a user form which asks for information
about the spreadsheet to use for output but this appears behind the
powerpoint window. Is there a way of forcing a userform to come to the front
of the desktop?

Grateful for ideas.
 
P

Peter T

All displayed windows are in front of the desktop, I expect you mean you
want your form to appear in front of Powerpoint. Depending on what you want
to do maybe simply appActivate is enough after displaying PP, eg
AppActivate Me.Caption

If you want to attach your form to your Powerpoint have a go with this -

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_HWNDPARENT = (-8)

Dim mPPhWnd As Long
Dim mFrmHwnd As Long


Private Sub CommandButton1_Click()
Dim oPP As Object

Set oPP = CreateObject("powerpoint.application")
oPP.Visible = True
mPPhWnd = FindWindow(vbNullString, oPP.Caption)

mFrmHwnd = FindWindow("ThunderDFrame", Me.Caption)

SetWindowLongA mFrmHwnd, GWL_HWNDPARENT, mPPhWnd
AppActivate Me.Caption
End Sub

Regards,
Peter T
 
S

simonc

I tried your suggestion but haven't made it work yet.

The main programme opens the userform with
frmOutputFile.Show
In the form code I tried putting
Appactivate me.caption
in a Private Sub UserForm_Initialize() subroutine, but it didn't bring the
form to the front. The Excel window title bar still flashes while waiting for
input from the form.

Do I need to put AppActivate in a different place?

thanks.
 
P

Peter T

How and when do you reference PowerPoint, and when do you show you form.

Regards,
Peter T
 
M

Martin Yirrell

Peter

Thanks for that, I think you've answered my question before I asked it. I've
not completely tried it out but it appears that if the form is set to non
modal (ShowModal=False) it does appear in front of the PowerPoint window.

regards
Martin
 
Top