PDA

View Full Version : Launching Excel from MS-Access / Detecting Excel to prevent multiple instances



tcarnahan
02-11-2015, 12:06 PM
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.



[*=1]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
[*=1]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

ZVI
02-11-2015, 03:00 PM
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

tcarnahan
02-12-2015, 01:28 PM
Thanks Vladimir ... I am going to give it a try.

snb
02-13-2015, 05:13 AM
I'm curious which code you used in Excel 2010 to perform this and would not function anymore in Excel 2013.

ZVI
02-13-2015, 04:38 PM
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