Activate an App by a Partial Window Title

Category:
Miscellaneous
Type:
Snippets
Difficulty:
Advanced
Author:
Intelligent Solutions Inc.

Version Compatibility: Visual Basic 6

More information:
VB's AppActivate function takes a string parameter and activates an application with a window title that either matches or begins with that parameter. This can cause a problem if you want to activate an application with a window caption that is not known. For example, IE displays the title of the current web page, followed by the string "Microsoft Internet Explorer", making it difficut to activate via the AppActivate function.

This example solves this problem by allowing you to pass a partial window title. The first application the system finds that contains the string you pass will be activated.

Because the AddressOf operator is used, you must put all the code (declarations and source) into a .bas module.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: