Run Other Applications
Being able to start one application from another is one of the significant advantages of Windows. Within Visual Basic you may want to start another application to load data from Excel, to display a web page, to edit text files, or to perform some other task not easily done in Excel itself. Visual Basic provides the functions shown in Table 3-19 to run other applications.
Table 3-19. Visual Basic functions for running other applications
|
Function |
Use to |
|---|---|
|
|
Switch focus to a running application |
|
|
Start an ActiveX application and get an object reference to that application |
|
|
Get a running ActiveX application and get an object reference to that application |
|
|
Send keystrokes to a running Windows application |
|
|
Start an application using its file (.exe) name |
CreateObject and GetObject work only with Windows applications that have support for ActiveX automation
built in to them. Most Microsoft products and many other Windows products support that type of automation, which is sometimes also called OLE automation
.
ActiveX or OLE automation allows you to use the internal objects, properties, and methods of the application in the same way that you control Excel from Visual Basic. For example, the following code starts Microsoft Word from Excel, creates a new document, inserts some text, and saves the file:
Sub UseWord( ) Dim word As Object, doc As Object Set word = CreateObject("Word.Application") ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access