Open Ole Object with VBA in front of the Excel Window

I have an excel spreadsheet with a video that is embeded as an OleObject.  I have code set on a button to open/activate the video. The code works fine except that sometimes the video opens in front of the excel window (as I want it to)  and sometimes it opens behind the window.  Is there code I can use to specify that it should open in front?

The code I have now is just:

Private Sub CommandButton2_Click()

Me.OLEObjects("Video").Activate

End Sub
amy_goeAsked:
Who is Participating?
 
Rgonzo1971Commented:
Hi,

pls try change line 5 for the name of the window

Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub WindowToFront()
    hWnd = FindWindow(vbNullString, "Video")
    If hWnd > 0 Then
        SetForegroundWindow (hWnd)
    End If
End Sub

Open in new window

Regards
0
 
amy_goeAuthor Commented:
That's seems to have done it.  Thank  you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.