Share via


Creating Microsoft Project 2002 Reports Using XML and XSL

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Summary

Microsoft® Project 2002 provides the ability to import and export files in Extensible Markup Language (XML). You can use exported XML files in many ways, including creating macros that apply Extensible Stylesheet Language (XSL) style sheets to generate Hypertext Markup Language (HTML) reports based on project data. This article describes how you can use XML and XSL to create Web page reports that contain Microsoft Project 2002 data.

Creating Microsoft Project 2002 Reports

You can create an HTML report against an active project in Microsoft Project 2002 by exporting that project as XML, applying an XSL style sheet, and then saving the data as an HTML file.

To generate an HTML file against the active project in Microsoft Project using Microsoft Visual Basic® for Applications (VBA), copy and paste the following code into the Microsoft Project VBA editor. Update the strings "C:\Project.xsl" and "C:\Report.htm" to reflect the location of the XSL file and where you want to create the HTML file.

  Public Sub GenerateWebPage()
  
      'This example shows how to generate HTML using XML exported from Microsoft Project 2002.
  
      Dim app As New MSProject.Application
      Dim htmlFile As String, xsltFile As String
      Dim XMLdoc, XSLdoc
  
      'Create an XML DOM document and save the project to it.
      Set XMLdoc = CreateObject("MSXML2.DOMdocument")
      XMLdoc.async = False
      app.FileSaveAs FormatID:="MSProject.XMLDOM", XMLName:=XMLdoc
  
      'Create an XML DOM document and load the transform.
      Set XSLdoc = CreateObject("MSXML2.DOMdocument")
      XSLdoc.async = False
      xsltFile = "c:\project.xsl"
      XSLdoc.Load xsltFile
  
      'Apply transform and save the resultant Web page.
      htmlFile = "c:\report.htm"
      Open htmlFile For Output As #1
      Print #1, XMLdoc.transformNode(XSLdoc)
      Close #1
  
      MsgBox "Web page updated"
  
  End Sub

Additional Information

For more information about the structure and contents of the Microsoft Project XML schema, see the file ProjXML.htm located in the \1033 folder (1033 is the locale ID [LCID] for U.S. English, the folder for localized versions will vary; for example, the LCID for Japanese is 1041) on your Microsoft Project 2002 CD. This file includes code samples that show how to open projects from (and save projects to) the XML Document Object Model (DOM), save projects that conform to the Microsoft Project XML schema, open projects from XML files, and open projects from strings of XML data.

For more information about Microsoft XML Core Services (MSXML) 4.0 (including information about the XML DOM), see the MSXML 4.0 SDK on MSDN.

For more information about how to create customized, advanced reports using Microsoft Office XP Web Components, read the SDK article Analyzing Microsoft Project 2002 Data with Microsoft Office XP Web Components and OLE DB.