Solved

In VBA how can I activate a non windows/Microsoft application and the close it?

Posted on 2010-11-16
12
602 Views
Last Modified: 2012-05-10
In a Excel VBA program  how do I first  identify and activate a non-Windows/Microsoft application and them close it? The program does not need to be saved so even using the X would work
0
Comment
Question by:macrohappy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 34148175
You could do something like this

Public Sub ActivateAndClose()

AppActivate "In VBA how can I activate a non windows/Microsoft application and the close it? - Mozilla Firefox"
SendKeys "%{F4}", True
End Sub

Open in new window


Thomas


Public Sub GetSAP2()

AppActivate "In VBA how can I activate a non windows/Microsoft application and the close it? - Mozilla Firefox"
application.Wait DateAdd("s", 1, Now)
SendKeys "%{F4}", True
End Sub

Open in new window

0
 

Author Comment

by:macrohappy
ID: 34148234
The window is Activating but "%{F4}", True is not closing it
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34148292
Is there a keyboard shortcut in that app to close it, apart from Alt + F4?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:macrohappy
ID: 34148336
No under FILE it just says SAVE or EXIT, no PF keys for shortcuts
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34148362
what program is it? And how do you access it if it's a non-windows application.

Thomas
0
 

Author Comment

by:macrohappy
ID: 34148397
it is an internal application and it is opened with a executable file. no different than you would open Quicken for example
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34148517
if you right-click the app on the task bar, I assume you have the restore, minimize, close Alt+F4 options?
0
 

Author Comment

by:macrohappy
ID: 34148594
Yes, sorry forgot about that. One thing to note. The program comes to the front when activated but the task bar is not highlighted. Not sure if that makes a difference
0
 
LVL 39

Expert Comment

by:nutsch
ID: 34148650
Are you running the macro with the wait or the one without?
How do you run it? Straight or step into?

T
0
 

Author Comment

by:macrohappy
ID: 34148672
ran it both ways, with the wait and without. I have been stepping into the macro
0
 

Author Comment

by:macrohappy
ID: 34148781
OK, I just ran the macro without stepping through it. One problem I get a pop up asking if I want to exit. Buttons are OK and Cancel
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 34149685
if the default is ok, then you can run the attached code.

If you step into, your appactivate is negated by the fact that the code has to reactivate the vb editor window to show you the steps.

Thomas
Public Sub ActivateAndClose()

AppActivate "In VBA how"
SendKeys "%{F4}", True 'send Alt+F4
application.Wait DateAdd("s", 1, Now)'wait 1 second for the popup
SendKeys "~", True 'send Enter

End Sub

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question