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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amy_goeAuthor Commented:
That's seems to have done it.  Thank  you!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.