Solved

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

Posted on 2010-11-16
12
591 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
  • 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
 

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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now