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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Also, you can simply use :
Code:
VBA.AppActivate [COLOR=#333333]excApp[/COLOR].Caption
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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