Skip to content

Latest commit

 

History

History
77 lines (48 loc) · 2.28 KB

Project.Application.OpenXML.md

File metadata and controls

77 lines (48 loc) · 2.28 KB
title ms.service api_name ms.assetid ms.date ms.localizationpriority
Application.OpenXML method (Project)
project-server
Project.Application.OpenXML
dcf3dd0e-78ec-b95c-b890-dca5507acd92
06/08/2017
medium

Application.OpenXML method (Project)

Opens a project from an XML string.

Syntax

expression. OpenXML( _XML_ )

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
XML Required String String containing a valid Project XML string that conforms to the Project XML schema.

Return value

Long

Remarks

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.

Example

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 
    Else 
        ' Open a text stream. 
        Set txtStream = fsObject.OpenTextFile(fileName:=fileName, IOMode:=ForReading) 
 
        xmlContents = txtStream.ReadAll 
        Application.OpenXML(xmlContents) 
        txtStream.Close 
    End If 
End Sub

[!includeSupport and feedback]