Need bullet-proof "bring Excel to front" code

Dougmeister

New Member
Joined
Sep 23, 2010
Messages
42
I've tried numerous code snippets over the years and none have worked 100%. I'm finally going to stick with this until I get it right this time.

1) It is being called from Outlook 2013
2) It needs to open up a specific workbook in Excel 2013

Once it gets that far, I'm good. I will do some stuff, save it, then close the workbook and exit Excel.

It would be bonus points to test to see if Excel has already been opened, if other workbooks are currently open, etc.

Current "solution" is as follows:

Code:
    Set excApp = CreateObject("Excel.Application")    Set excBook = excApp.Workbooks.Open(strPath & strFileName)
    Set excSheet = excBook.ActiveSheet
    excApp.Visible = True

The problem is that it does not bring the window to the front. I've tried various API declarations in the past, including:

Code:
'Private Declare Function BringWindowToTop Lib "user32" (ByVal HWnd As Long) As Long
'Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Private Declare Function SetFocus Lib "user32" (ByVal HWnd As Long) As Long

Help? Thanks.
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Also, you can simply use :
Code:
VBA.AppActivate [COLOR=#333333]excApp[/COLOR].Caption
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top