PDA

View Full Version : Switch to a specific open application



spphat
07-30-2009, 07:38 PM
Hi - I'm fairly new to VBA, and I've been programming in Excel 2000. Its pretty much finished, but I keep adding little bits and pieces here and there. What I want to do now is open an already opened application, BUT, there are multiple applications (up to 6) that are also open, so AppActivate would not work because I need to open up one of the specific 6, not just any one of them.

Some background about the project: Theres a spreadsheet with client information, and I use this spreadsheet to check for additional information in above mentioned application, call it XYZ. XYZ takes awhile to bring back results, so I typically open up 5 or 6 XYZ applications. I need to "tag" the specific XYZ app so I know which spreadsheet goes with which XYZ.

This might be a little confusing, so I basically just need a way to access/activate a specific application out of a group of many. Thanks for any help that might be provided.

Benzadeus
07-31-2009, 07:39 AM
Usually, when an application opens a file, it displays in the title the name of the opened file.

Assuming this AND you open up to 6 different files, you could use:

Sub ActivateSpecificWindow()

AppActivate "XYZ - File1"
'do actions

AppActivate "XYZ - File2"
'do actions

AppActivate "XYZ - File3"
'do actions

AppActivate "XYZ - File4"
'do actions

End Sub

spphat
07-31-2009, 08:19 AM
Hi Benzadeus - Thanks for your reply. The thing with the app though is that the names aren't like that. Each app is individually called "XYZ", so I cannot reference the specific one by AppActivate. Thanks for the help though!

Benzadeus
07-31-2009, 10:23 AM
Well, just two questions...

1 - The XYZ Apps are created in the macro as objects or do you first open the Apps and after that you run the macro?

2 - Do you use SendKeys method in your code?

spphat
07-31-2009, 10:56 AM
1 - I don't have to use the macro to create them. I will typically already have them opened before the macro runs (I have to log-in to them).

2 - I will be using SendKeys to populate the XYZ application. This is fairly easy to do, and believe I have a good handle of Sendkeys to do this. The hard part is just picking a particular instance of XYZ.

Benzadeus
07-31-2009, 11:09 AM
So why don't use ALT+TAB in SendKeys to alternate between them???

I read this KB entry http://www.vbaexpress.com/kb/getarticle.php?kb_id=811 and was wondering, as described in the line
intError = objProcess.Terminate 'Terminates a process and all of its threads.

if it is possible change .Terminate for something like .GotFocus, .Activate, .Visible = True, but I had no success.

Maybe someone else can help us.

spphat
07-31-2009, 11:34 AM
ALT-TAB won't work correctly, because the searches on the other application vary in time: some take 10 minutes, some only 2 minutes. So the placement of the app will not be correct if I just do ALT-TAB.