Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0)
How to: Create New Documents

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

When you create a document programmatically, the new document is a native Microsoft.Office.Interop.Word..::.Document object. This object does not have the additional events and data binding capabilities of a Microsoft.Office.Tools.Word..::.Document host item. For more information, see Programmatic Limitations of Host Items and Host Controls.

Starting in SP1, you can use application-level add-ins to convert any Microsoft.Office.Interop.Word..::.Document object to a Microsoft.Office.Tools.Word..::.Document host item. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.

When you develop a document-level project, you cannot programmatically add Microsoft.Office.Tools.Word..::.Document host items to your project.

To create a new document based on Normal.dot

  • Use the Add method of the Documents collection to create a new document based on Normal.dot.

    Visual Basic
    Me.Application.Documents.Add()
    
    C#
    this.Application.Documents.Add(ref missing, ref missing, ref missing, ref missing);
    
Using Custom Templates

The Add method has an optional Template argument to create a new document based on a template other than Normal.dot. You must supply the file name and fully qualified path of the template.

To create a new document based on a custom template

  • Call the Add method of the Documents collection and specify the path to the template.

    Visual Basic
    Me.Application.Documents.Add(Template:="C:\Test\SampleTemplate.Dot")
    
    C#
    object template = @"C:\Test\SampleTemplate.dot"; 
    this.Application.Documents.Add(ref template, ref missing, ref missing, ref missing);
    
See Also

Tasks

Concepts

Tags :


Page view tracker