Results 1 to 4 of 4
  1. #1
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79

    Invoked Application on top of screen

    Hi,



    I'm using Excel to draw my (quite complicated) reports invoked from Access. However I don't always get Excel Application on top of screen after code is executed. Anyone knows how to ensure that Excel Window is on top of screen after execued code?

    Code:
    Public gappExcel As Excel.Application
    
    Sub Test()
        '...
        If gappExcel Is Nothing Then Set gappExcel = New Excel.Application
        gappExcel.Visible = True
        '...
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    DoCmd.RunCommand acCmdAppMinimize
    If gappExcel Is Nothing Then Set gappExcel = New Excel.Application
    gappExcel.Visible = True

  3. #3
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    Thanks,

    That worked fine.

    One follow up question. If I have 2 screens:
    - Excel and Access are on distinguished screens. DON'T MINIMIZE ACCESS
    - Excel and Access are on same screens. MINIMIZE ACCESS

    Any idea how to identify which screen the application is visible?

    I found the property .Left in Excel applcation. Maybe possible to use. But I couldn't find .Left in Access application. Any idea how to find the position of Access application?

    (I use a Windows API to get the screen resolution for my comparison)

    Code:
    Dim dLeftAccess As Double
    Dim dLeftExcel As Double
    
    dLeftExcel = gappExcel.Left
    'dLeftAccess = ?
    
    If gappExcel Is Nothing Then Set gappExcel = New Excel.Application
    gappExcel.Visible = True
    
    'Hide Access?
    'if MY_CONDITION then
        DoCmd.RunCommand acCmdAppMinimize
    'End If

  4. #4
    Joakim N is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    Oct 2016
    Posts
    79
    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

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-16-2016, 08:17 AM
  2. Replies: 1
    Last Post: 08-08-2014, 06:35 AM
  3. Replies: 1
    Last Post: 05-09-2013, 07:54 PM
  4. Replies: 1
    Last Post: 02-25-2012, 01:14 PM
  5. Wizard not opening when tool invoked
    By MiriamK in forum Access
    Replies: 4
    Last Post: 12-01-2011, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums