Article ID: 302281 - Last Review: March 29, 2007 - Revision: 7.5 How to obtain the window handle for an Office Automation server by using Visual Basic .NETThis article was previously published under Q302281 On This PageSUMMARY This article demonstrates how to obtain the window handle
of a Microsoft Office application while automating that application from
Microsoft Visual Basic .NET. MORE INFORMATION The object models for most Office applications do not
expose properties for retrieving the application window handles. To determine
the window handle of an Office application that you are automating, you can use
the FindWindow function with the class name of the topmost window for the
application. If the application can have multiple instances running at the same
time, you may need to account for this so that you retrieve the correct window
handle. The following sections illustrate techniques for retrieving the window
handle for both single and multiple instance applications. Note The Microsoft Access object model exposes the hWndAccessApp property for the Application object for determining the window handle of the application. You can also use the hWnd property for Forms and Reports to retrieve handles to those specific windows. Additionally, Microsoft Excel 2002 is the first version of Excel to introduce an hWnd property for its Application object. Regarding Excel 2002 and later and Microsoft Access 97 and later, the FindWindow approach that is discussed in this article is not necessary because these Office applications can retrieve the window handle for the application through their respective object models. Find the window handle for an application that is a single instanceThe following steps illustrate how you can use the FindWindow function with a Visual Basic Automation client to determine the window handle for an out-of-process Automation server that can have only a single instance. This is the technique that you employ when you use Microsoft PowerPoint as your Automation server.Step-by-step example
Find the window handle for an application that can have multiple instancesSome applications, such as Microsoft Excel or Microsoft Word, can have multiple instances running at the same time. To retrieve the handle to the application instance that you are automating, you can first use Automation to change the title of the application to a unique value and then use the FindWindow function to retrieve its window handle. The following steps illustrate this technique by using Excel as the Automation server.Step-by-step example
REFERENCES For more information, visit the following Microsoft
Developer Network (MSDN) Web site: Microsoft Office Development with Visual Studio For
more information about retrieving the window handle for an Office Automation
server by using earlier versions of Visual Basic, click the following article
number to view the article in the Microsoft Knowledge Base: http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx (http://msdn2.microsoft.com/en-us/library/aa188489(office.10).aspx) 258511
(http://support.microsoft.com/kb/258511/
)
How to obtain the window handle for an Office Automation server
APPLIES TO
| Article Translations
|
Back to the top
