Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Automating InfoPath from an External Application

Last modified: July 24, 2009

Applies to: InfoPath 2010 | Office 2010 | Visual Studio 2010

Microsoft InfoPath 2010 provides application automation from code written using COM and script by using methods of the Application object and the XDocuments collection.

The Application object contains the following methods used for automation:

Method

Description

CacheSolution

Examines the in the cache and, if necessary, updates it from the published location of the form template.

Quit

Quits the Microsoft Office InfoPath application.

RegisterSolution

Installs the specified Microsoft Office InfoPath form template.

UnregisterSolution

Uninstalls the specified Microsoft Office InfoPath form template.

The XDocuments collection contains the following methods that can be used for external automation:

Method

Description

Close method

Closes the specified Microsoft Office InfoPath form.

New method

Creates a new Microsoft Office InfoPath form.

NewFromSolution method

Creates a new Microsoft Office InfoPath form based on the specified form template.

NewFromSolutionWithData method

Creates a new Microsoft Office InfoPath form using the specified XML data and form template.

Open method

Opens the specified Microsoft Office InfoPath form.

To use the Application object from an external application, you use the CreateObject function with the ProgID of the InfoPath application ("InfoPath.Application") to create an object variable that represents the InfoPath application. You can then use the XDocuments property to access the XDocuments collection and use its methods to open or create an InfoPath form. The following example demonstrates the creation of a reference to the Application object using the Microsoft Visual Basic 6.0 or Visual Basic for Applications (VBA) programming language:

Dim objIP As Object 
 
Set objIP = CreateObject("InfoPath.Application") 
 
' Open an existing form 
objIP.XDocuments.Open ("C:\MyFolder\MyForm.xml") 
 
' Create a new form based on a form template 
objIP.XDocuments.NewFromSolution ("C:\MyFolder\MyForm.xsn") 

NoteNote

Because the CreateObject function creates an object variable using late binding, automatic statement completion will not be available in the Visual Basic Editor. Refer to the links in the preceding tables for information about the correct calling syntax.

Show:
© 2015 Microsoft