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
Solved

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

Posted on 2010-11-16
12
597 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

837 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