Results 1 to 5 of 5

Thread: Forcing focus

  1. #1
    Platinum Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    5,646
    Thanks
    54
    Thanked 9 Times in 8 Posts
    I have a macro in Outlook or Word

    Sub PSACards()
    Shell ("C:\WinApps\Info\PSA Cards\cards.exe"), vbNormalFocus
    End Sub

    It runs fine, but it opens the program behind the App the macro is in.

    Is there a way to force the window of the newly opened App to the front?

    Regards,
    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could try the Appactivate method.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,015
    Thanks
    0
    Thanked 3 Times in 3 Posts
    To give more info on AppActivate

    You should be able to get the Windows ID return handle from the shell function

    Then pass that to AppActivate

    The Function below shows that with Notepad
    Although Notepad does not need it because it does get the focus

    Code:
    Dim lngHWnd As Long
    
    lngHWnd = Shell("C:\Windows\Notepad.exe", vbNormalFocus)
    
    AppActivate lngHWnd, True
    Andrew

  4. #4
    Platinum Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    5,646
    Thanks
    54
    Thanked 9 Times in 8 Posts
    Pieter / Andrew;

    Thanks. I'll see if I can set that up to help.

    Regards,
    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  5. #5
    Platinum Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    5,646
    Thanks
    54
    Thanked 9 Times in 8 Posts
    Quote Originally Posted by AKW View Post
    To give more info on AppActivate

    You should be able to get the Windows ID return handle from the shell function

    Then pass that to AppActivate

    The Function below shows that with Notepad
    Although Notepad does not need it because it does get the focus

    Code:
    Dim lngHWnd As Long
    
    lngHWnd = Shell("C:\Windows\Notepad.exe", vbNormalFocus)
    
    AppActivate lngHWnd, True
    AKW, that seems to have done it. I'm not familiar enough with VBA to understand the Hows or whys, but it did the job.

    Thanks,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Posting Permissions

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