Table of contents
Collapse the table of content
Expand the table of content

Application.OpenXML Method (Project)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

Opens a project from an XML string.


expression. OpenXML( ** XML** )

expression A variable that represents an Application object.


NameRequired/OptionalData TypeDescription
XMLRequiredStringString containing a valid Project XML string that conforms to the Project XML schema.

Return Value



The Project XML schema is available in the Project SDK, as the file mspdi_pj15.xsd. You can create an XML file by saving a project to XML, and then editing the file. If you programmatically create an XML string, you should validate it against the schema before using it with the OpenXML method.

The OpenXML method returns 0 if it is successful.

Note You can also use the FileOpenEx method to open a valid Project XML file. The OpenXML method is primarily designed to open a project by using an XML string.


The following example opens a file named OneTaskEdited.xml that was created by saving a project as XML and then editing the file to remove default values. The example requires a reference to the Microsoft Scripting Runtime library (scrrun.dll).

Sub ImportXMLProject() 
    ' Requires reference to the Microsoft Scripting Runtime library (scrrun.dll). 
    Dim txtStream As TextStream 
    Dim fileName As String 
    Dim xmlContents As String 
    Dim fsObject As FileSystemObject 

    fileName = "C:\Project\VBA\Samples\OneTaskEdited.xml" 
    Set fsObject = CreateObject("Scripting.FileSystemObject") 

    If Not fsObject.FileExists(fileName) Then 
        MsgBox "The file does not exist: " &; vbCrLf &; fileName 
        ' Open a text stream. 
        Set txtStream = fsObject.OpenTextFile(fileName:=fileName, IOMode:=ForReading) 

        xmlContents = txtStream.ReadAll 
    End If 
End Sub
© 2018 Microsoft