Hi,
I solved it by using API-functions in following order:
1. Excel application on top of screen
2. Workbook on top of screen
I have attached the code if anyone is interested.
Code:
'Show Application/Window on top of screen
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
'Find a child window with a given class name and caption
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) _
As Long
Public gappExcel As Excel.Application
Sub ExcekWkbkOnTopOfScreen(sWkbName As String)
Dim lhWndExcelApp As Long
Dim lhWndExcelWkb As Long
If Not gappExcel Is Nothing Then
'Excel application on top
lhWndExcelApp = gappExcel.hwnd
BringWindowToTop (lhWndExcelApp)
'Wkb on top
lhWndExcelWkb = WorkbookWindowhWnd(gappExcel.Windows(sWkbName))
BringWindowToTop (lhWndExcelWkb)
End If
End Sub
Function WorkbookWindowhWnd(ByRef wndWindow As Window) As Long
'Get handle of Excel Workbook
Dim lhWndExcel As Long
Dim lhWndDesk As Long
'Get the main Excel window
lhWndExcel = gappExcel.hwnd
'Find the desktop
lhWndDesk = FindWindowEx(lhWndExcel, 0, "XLDESK", vbNullString)
'Find the workbook window
WorkbookWindowhWnd = FindWindowEx(lhWndDesk, 0, "EXCEL7", wndWindow.Caption)
End Function
Sub Test()
Call ExcekWkbkOnTopOfScreen("MyWkb.xlsx")
End Sub