Question

I'm using a UserForm spawned by Excel that modifies a PowerPoint presentation (it's a roundabout way to avoid needing a macro-enabled spreadsheet). The form works just fine, but every time I focus to it the Excel application takes focus (since Excel is the parent window).

Is there any way to stop this from happening? I'd like to prevent Excel from taking focus when the UserForm is used.

Was it helpful?

Solution

Would something like this work? This will hide/make invisible the parent Excel Application while the UserForm is displayed. Or at least get you started:

Example subroutine that "Shows" the userform:

Sub Test()

Dim ppt As Object
Dim xl As Object
Set ppt = GetObject(, "PowerPoint.Application")
Application.Visible = False
UserForm1.Show vbModeless

End Sub

Use this in the form's Terminate event:

Private Sub UserForm_Terminate()
    'Ensures the Excel Application is visible after the form closes
    Application.Visible = True
End Sub

You could add a button/etc on the form, if you want to allow the user to unhide the Excel Application

Private Sub CommandButton1_Click()
    'Displays the Excel Application:
    Application.Visible = True
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top