PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

VBA to set focus back to exel

 
 
Waxaholic
Guest
Posts: n/a
 
      14th Jan 2008
I am launching an external application from excel and need to obtain
control of excel after the external program launches. This is all done
via VBA. VBA wants to wait for the installation to finish before
giving me excel back. I need to overcome this and have immediate
control of excel so i can close the workbook. Any ideas.

thanks

Brian
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      15th Jan 2008
Try this:

Option Explicit
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As
Long) As Long

Sub XLFocus()

Dim lExcelHwnd As Long

lExcelHwnd = FindWindow("XLMAIN", Application.Caption)
SetForegroundWindow lExcelHwnd

End Sub


RBS


"Waxaholic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am launching an external application from excel and need to obtain
> control of excel after the external program launches. This is all done
> via VBA. VBA wants to wait for the installation to finish before
> giving me excel back. I need to overcome this and have immediate
> control of excel so i can close the workbook. Any ideas.
>
> thanks
>
> Brian


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jan 2008
Untested...

AppActivate Application.Caption

Waxaholic wrote:
>
> I am launching an external application from excel and need to obtain
> control of excel after the external program launches. This is all done
> via VBA. VBA wants to wait for the installation to finish before
> giving me excel back. I need to overcome this and have immediate
> control of excel so i can close the workbook. Any ideas.
>
> thanks
>
> Brian


--

Dave Peterson
 
Reply With Quote
 
Waxaholic
Guest
Posts: n/a
 
      15th Jan 2008
Thanks to all. I have tried both recommendations above and they do
work, however, they are real slow (about 30sec or more) in returning
focus. This is way too long and would allow the end user to screw
things up. I am trying to get an instantaneous return of focus as soon
as the external app launches.

What i have is some vba that checks for an update to the excel
workbook. It then allows the user to download the update and the
additional option of installing it. This is where i launch the
installer and want to return to excel and close the workbook before
the user can continue with the installer.

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jan 2008
I don't have another suggestion.

Waxaholic wrote:
>
> Thanks to all. I have tried both recommendations above and they do
> work, however, they are real slow (about 30sec or more) in returning
> focus. This is way too long and would allow the end user to screw
> things up. I am trying to get an instantaneous return of focus as soon
> as the external app launches.
>
> What i have is some vba that checks for an update to the excel
> workbook. It then allows the user to download the update and the
> additional option of installing it. This is where i launch the
> installer and want to return to excel and close the workbook before
> the user can continue with the installer.


--

Dave Peterson
 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      15th Jan 2008
Maybe you could post your code.

RBS


"Waxaholic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks to all. I have tried both recommendations above and they do
> work, however, they are real slow (about 30sec or more) in returning
> focus. This is way too long and would allow the end user to screw
> things up. I am trying to get an instantaneous return of focus as soon
> as the external app launches.
>
> What i have is some vba that checks for an update to the excel
> workbook. It then allows the user to download the update and the
> additional option of installing it. This is where i launch the
> installer and want to return to excel and close the workbook before
> the user can continue with the installer.
>


 
Reply With Quote
 
Waxaholic
Guest
Posts: n/a
 
      15th Jan 2008
Version 1:
Sub Launcher()
Dim lExcelHwnd As Long

lExcelHwnd = FindWindow("UMR Creator v0_32wu", Application.Caption)

Shell ThisWorkbook.Path & "\" & Sheets("MenuSheet").Range("K2") &
".exe", vbNormalNoFocus

SetForegroundWindow lExcelHwnd

End Sub

Version 2:
----------------------------------------------------
Sub Launcher2()

Dim MyAppID, ReturnValue
Dim UMRCID As Long

MyAppID = ("UMR Creator v0_32wu")

UMRCID = Shell(ThisWorkbook.Path & "\" &
Sheets("MenuSheet").Range("K2") & ".exe", 6)
AppActivate MyAppID, 0

End Sub


Both of these work for me but the delay coming back to excel is way
too long.



On Jan 15, 1:38 am, "RB Smissaert" <(E-Mail Removed)>
wrote:
> Maybe you could post your code.
>
> RBS
>
> "Waxaholic" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Thanks to all. I have tried both recommendations above and they do
> > work, however, they are real slow (about 30sec or more) in returning
> > focus. This is way too long and would allow the end user to screw
> > things up. I am trying to get an instantaneous return of focus as soon
> > as the external app launches.

>
> > What i have is some vba that checks for an update to the excel
> > workbook. It then allows the user to download the update and the
> > additional option of installing it. This is where i launch the
> > installer and want to return to excel and close the workbook before
> > the user can continue with the installer.- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      15th Jan 2008
A few things:

What is this: "UMR Creator v0_32wu" ?
Did you try with "XLMAIN" ?

Try a DoEvents before SetForegroundWindow lExcelHwnd


RBS


"Waxaholic" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Version 1:
> Sub Launcher()
> Dim lExcelHwnd As Long
>
> lExcelHwnd = FindWindow("UMR Creator v0_32wu", Application.Caption)
>
> Shell ThisWorkbook.Path & "\" & Sheets("MenuSheet").Range("K2") &
> ".exe", vbNormalNoFocus
>
> SetForegroundWindow lExcelHwnd
>
> End Sub
>
> Version 2:
> ----------------------------------------------------
> Sub Launcher2()
>
> Dim MyAppID, ReturnValue
> Dim UMRCID As Long
>
> MyAppID = ("UMR Creator v0_32wu")
>
> UMRCID = Shell(ThisWorkbook.Path & "\" &
> Sheets("MenuSheet").Range("K2") & ".exe", 6)
> AppActivate MyAppID, 0
>
> End Sub
>
>
> Both of these work for me but the delay coming back to excel is way
> too long.
>
>
>
> On Jan 15, 1:38 am, "RB Smissaert" <(E-Mail Removed)>
> wrote:
>> Maybe you could post your code.
>>
>> RBS
>>
>> "Waxaholic" <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > Thanks to all. I have tried both recommendations above and they do
>> > work, however, they are real slow (about 30sec or more) in returning
>> > focus. This is way too long and would allow the end user to screw
>> > things up. I am trying to get an instantaneous return of focus as soon
>> > as the external app launches.

>>
>> > What i have is some vba that checks for an update to the excel
>> > workbook. It then allows the user to download the update and the
>> > additional option of installing it. This is where i launch the
>> > installer and want to return to excel and close the workbook before
>> > the user can continue with the installer.- Hide quoted text -

>>
>> - Show quoted text -

>


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jan 2008
In launcher2, use this:
AppActivate Application.Caption
(don't change it)



Waxaholic wrote:
>
> Version 1:
> Sub Launcher()
> Dim lExcelHwnd As Long
>
> lExcelHwnd = FindWindow("UMR Creator v0_32wu", Application.Caption)
>
> Shell ThisWorkbook.Path & "\" & Sheets("MenuSheet").Range("K2") &
> ".exe", vbNormalNoFocus
>
> SetForegroundWindow lExcelHwnd
>
> End Sub
>
> Version 2:
> ----------------------------------------------------
> Sub Launcher2()
>
> Dim MyAppID, ReturnValue
> Dim UMRCID As Long
>
> MyAppID = ("UMR Creator v0_32wu")
>
> UMRCID = Shell(ThisWorkbook.Path & "\" &
> Sheets("MenuSheet").Range("K2") & ".exe", 6)
> AppActivate MyAppID, 0
>
> End Sub
>
> Both of these work for me but the delay coming back to excel is way
> too long.
>
> On Jan 15, 1:38 am, "RB Smissaert" <(E-Mail Removed)>
> wrote:
> > Maybe you could post your code.
> >
> > RBS
> >
> > "Waxaholic" <(E-Mail Removed)> wrote in message
> >
> > news:(E-Mail Removed)...
> >
> >
> >
> > > Thanks to all. I have tried both recommendations above and they do
> > > work, however, they are real slow (about 30sec or more) in returning
> > > focus. This is way too long and would allow the end user to screw
> > > things up. I am trying to get an instantaneous return of focus as soon
> > > as the external app launches.

> >
> > > What i have is some vba that checks for an update to the excel
> > > workbook. It then allows the user to download the update and the
> > > additional option of installing it. This is where i launch the
> > > installer and want to return to excel and close the workbook before
> > > the user can continue with the installer.- Hide quoted text -

> >
> > - Show quoted text -


--

Dave Peterson
 
Reply With Quote
 
Waxaholic
Guest
Posts: n/a
 
      15th Jan 2008
Thanks to both of you but i still get the same result in slowness.

The "UMR Creator v0_32wu" is the window handle for the excel workbook.
I played with this and tried using XLMAIN, as well as a few different
variations in code and no speed increase. I am thinking of another
approach like launching a helper xls file with the Launcher code in
it. This would allow me to close the existing workbook without
problem. I'll report back if it works.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
set focus not "setting focus" Mark J Kubicki Microsoft Access Form Coding 3 12th Nov 2006 07:15 PM
How to set a back ground picture in an exel file =?Utf-8?B?RGl2eWE=?= Microsoft Excel Worksheet Functions 2 30th Jun 2006 06:03 PM
how do I convert a non exel tabulation to exel =?Utf-8?B?ZHRlMTIz?= Microsoft Excel New Users 2 30th Jun 2006 02:31 AM
set focus for field just losing focus AngiW Microsoft Access VBA Modules 3 3rd Feb 2004 07:07 AM
set focus on next tab when last field loses focus mcnewsxp Microsoft Access Form Coding 4 17th Dec 2003 03:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:57 AM.