Results 1 to 6 of 6
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    If I have the following macro to call a program

    Sub NEO()
    Shell ("C:\Program Files\NEO Pro\NEOPro.exe"), vbNormalFocus
    End Sub

    What do I need to add so that if it already there, minimized to the Taskbar, that it will be "maximized" and given focus?

    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
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Chuck,

    The following code solves part of the problem, i.e. remembering that the program is open and providing a programID. However It will not maximize the program, at lest not the way I tried. I couldn't find anything on the internet but I only did a quick search. I'll keep looking. Maybe someone else can provide the missing part.
    Code:
    Sub CallPgm()
    
       'Note: oMyPgm has to be declared {Variant} Public so it's around next time the code is called.
    
       If IsEmpty(oMyPgm) Then
         oMyPgm = Shell("C:\Windows\explorer.exe", vbNormalFocus)  '*** This works ***
         MsgBox "ProgramID: " & Format(oMyPgm)
       Else
         oMyPgm.Maximize   '*** This does not work ***
       End If
       
    End Sub
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by RetiredGeek View Post
    Chuck,

    The following code solves part of the problem, i.e. remembering that the program is open and providing a programID. However It will not maximize the program, at lest not the way I tried. I couldn't find anything on the internet but I only did a quick search. I'll keep looking. Maybe someone else can provide the missing part.
    Code:
    Sub CallPgm()
    
       'Note: oMyPgm has to be declared {Variant} Public so it's around next time the code is called.
    
       If IsEmpty(oMyPgm) Then
     	oMyPgm = Shell("C:\Windows\explorer.exe", vbNormalFocus)  '*** This works ***
     	MsgBox "ProgramID: " & Format(oMyPgm)
       Else
     	oMyPgm.Maximize   '*** This does not work ***
       End If
       
    End Sub

    Thanks RG!

    Regards,
    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"

  4. #4
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by RetiredGeek View Post
    Chuck,

    The following code solves part of the problem, i.e. remembering that the program is open and providing a programID. However It will not maximize the program, at lest not the way I tried. I couldn't find anything on the internet but I only did a quick search. I'll keep looking. Maybe someone else can provide the missing part.
    Code:
    Sub CallPgm()
    
       'Note: oMyPgm has to be declared {Variant} Public so it's around next time the code is called.
    
       If IsEmpty(oMyPgm) Then
     	oMyPgm = Shell("C:\Windows\explorer.exe", vbNormalFocus)  '*** This works ***
     	MsgBox "ProgramID: " & Format(oMyPgm)
       Else
     	oMyPgm.Maximize   '*** This does not work ***
       End If
       
    End Sub
    RG;

    Here is exactly what I pasted in

    Sub NEO()
    'Note: oMyPgm has to be declared {Variant} Public so it's around next time the code is called.
    If IsEmpty(oMyPgm) Then
    oMyPgm = Shell("C:\Program Files\NEO Pro\NEOPro.exe", vbNormalFocus) '*** This works ***
    MsgBox "ProgramID: " & Format(NEO)
    'Else
    oMyPgm.Maximize '*** This does not work ***
    End If
    End Sub

    And I got the error
    "Expected function or variable"

    with the Forat(NEO) in line 5 highlighted.

    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"

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,434
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Chuck,

    Ok I got it to work. Unfortunately I had to use Internet Explorer since I don't have your program. The only thing you need to change in the code is the string in the Shell command that executes your program.
    Code:
    Sub CallPgm()
    
    ' Define this outside of any Sub at the top of a Module
    ' Public oMyPgm As Variant
    
       If IsEmpty(oMyPgm) Then
         oMyPgm = Shell("C:\Program Files\Internet Explorer\iexplore.exe", vbNormalFocus)
         MsgBox "ProgramID: " & Format(oMyPgm)   '*** For Testing ONLY ***
       Else
         AppActivate oMyPgm   '*** Activate Program on Task bar                      ***
         SendKeys "% "             '*** Maximize selected program Alt+spacebar ***
         SendKeys "x"                '***          then x                                                     ***
       End If
       
    End Sub
    Update: You can auto minimize the app when you open it with:
    SendKeys "% " '*** Alt+Spacebar
    SendKeys "n"
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by RetiredGeek View Post
    Chuck,

    Ok I got it to work. Unfortunately I had to use Internet Explorer since I don't have your program. The only thing you need to change in the code is the string in the Shell command that executes your program.
    Code:
    Sub CallPgm()
    
    ' Define this outside of any Sub at the top of a Module
    ' Public oMyPgm As Variant
    
       If IsEmpty(oMyPgm) Then
    	oMyPgm = Shell("C:\Program Files\Internet Explorer\iexplore.exe", vbNormalFocus)
    	MsgBox "ProgramID: " & Format(oMyPgm)   '*** For Testing ONLY ***
       Else
    	AppActivate oMyPgm   '*** Activate Program on Task bar                      ***
    	SendKeys "% "     		'*** Maximize selected program Ctrl+spacebar ***
    	SendKeys "x"                '***          then x                                             		***
       End If
       
    End Sub
    That works Great!

    Thanks RG!

    Regards,
    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
  •