Consulting

Results 1 to 5 of 5

Thread: Launching Excel from MS-Access / Detecting Excel to prevent multiple instances

  1. #1
    VBAX Newbie tcarnahan's Avatar
    Joined
    Jul 2007
    Location
    Fairfax
    Posts
    4
    Location

    Launching Excel from MS-Access / Detecting Excel to prevent multiple instances

    I just moved from MS-Office 2010 to MS-Office 2013. I had several sections of VBA code that I used successfully before that no longer work. The VBA code is in my MS-Access application and is used to manipulate MS-Excel.


    • Detect Excel: a call to the DLL that checked if Excel was already running. If it was running, then it would add the new instance to the "running list". If it was not running, it would start up a new instance
    • Bring Excel Window to the Foreground: a call to the DLL that identified the Excel window and brought it into focus in the foreground.


    Since going to 2013, these no longer work. There is some information out on the web about converting over some DLL calls but it is not clear how to perform the two functions above.

    Question: can anyone point me to some clear documentation of the correct substitute code to call the DLL and perform those two functions in the MS-Office 2013 environment?

    Thanks,
    Tom
    -- Tom

  2. #2
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Hi Tom,

    VBA can do it. The below code works with Excel 2013 as well, without dependence on 32/64bit by the way.

    Sub ActivateExcel2013()
     
      Dim objExcel As Object
     
      ' Find an existent Excel application
      On Error Resume Next
      Set objExcel = GetObject(, "Excel.Application")
      If Err Then
        ' Excel not found - create new instance
        Set objExcel = CreateObject("Excel.Application")
      End If
      On Error GoTo 0
     
      ' Bring Excel window to the foreground (Excel 2013 compatible)
      AppActivate objExcel.Caption
     
    End Sub
    Regards,
    Vladimir
    Last edited by ZVI; 02-11-2015 at 03:14 PM.

  3. #3
    VBAX Newbie tcarnahan's Avatar
    Joined
    Jul 2007
    Location
    Fairfax
    Posts
    4
    Location
    Thanks Vladimir ... I am going to give it a try.
    -- Tom

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I'm curious which code you used in Excel 2010 to perform this and would not function anymore in Excel 2013.

  5. #5
    VBAX Contributor
    Joined
    Dec 2009
    Location
    Sevastopol
    Posts
    150
    Location
    Quote Originally Posted by snb View Post
    I'm curious which code you used in Excel 2010 to perform this and would not function anymore in Excel 2013.
    AppActivate "Microsoft Excel" works in Excel 2010 but causes an error to Excel 2013 (because its caption is "Excel").
    AppActivate Application.Caption works well in all versions

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •