For a Microsoft Visual Basic .NET version of this article, see
- Microsoft presents Microsoft Word for processing the best-edited text applications. Word is the most commonly used application since its release. From new learners to professionals, Microsoft Word gives support on a stunning level.
- Word for Microsoft 365 Word for Microsoft 365 for Mac Word 2019 Word 2016 Word for iPad Word for iPhone Word for Android tablets Whiteboard Word for Android phones More. Less As a Microsoft 365 subscriber, you regularly get new and improved Office features.
New Microsoft Word Email
Microsoft is overhauling its Office 365 subscription with a new focus on consumers, changing the name to Microsoft 365 and throwing in tons of new features for Word, Excel, PowerPoint, Outlook.
Summary
This step-by-step article describes how to create a new document in Microsoft Word by using Automation from Microsoft Visual C# 2005 or Microsoft Visual C# .NET.
New Microsoft Word Version
Sample Code
The sample code in this article demonstrates how to do the following:
- Insert paragraphs with text and formatting.
- Browse and modify various ranges within a document.
- Insert tables, format tables, and populate the tables with data.
- Add a chart.
New Microsoft Word Update
To create a new Word document by using Automation from Visual C# 2005 or Visual C# .NET, follow these steps:
Start Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET.
On the File menu, click New, and then click Project. Under Project Types, click Visual C# Projects, and then click Windows Application under Templates. Form1 is created by default.
Note In Visual Studio 2005, click Visual C# instead of Visual C# Projects.
Add a reference to Microsoft Word Object Library. To do this, follow these steps:
- On the Project menu, click Add Reference.
- On the COM tab, locate Microsoft Word Object Library, and then click Select.
Note In Visual Studio 2005, you do not have to click Select.
Note Microsoft Office 2003 includes Primary Interop Assemblies (PIAs). Microsoft Office XP does not include PIAs, but they can be downloaded.
- Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the libraries that you selected, click Yes.
On the View menu, select Toolbox to display the Toolbox, and then add a button to Form1.
Double-click Button1. The code window for the form appears.
In the code window, replace the following code:
with:
Scroll to the top of the code window. Add the following line to the end of the list of using directives:
Press F5 to build and to run the program.
Click Button1 to start Word Automation and to create the document.
After the code completes, examine the document that was created for you. The document contains two pages of formatted paragraphs, tables, and a chart.
Use a Template
New Microsoft Word Free Download
If you are using Automation to build documents that are all in a common format, you can benefit from starting the process with a new document that is based on a preformatted template. Using a template with your Word Automation client has two significant advantages over building a document from nothing:
- You can have greater control over the formatting and placement of objects throughout your documents.
- You can build your documents with less code.
By using a template, you can fine-tune the placement of tables, paragraphs, and other objects within the document, as well as include formatting on those objects. By using Automation, you can create a new document based on your template with code such as the following:
In your template, you can define bookmarks so that your Automation client can fill in variable text at a specific location in the document, as follows:
Another advantage to using a template is that you can create and store formatting styles that you wish to apply at runtime, as follows:
New Microsoft Word 2017
or
References
For more information, view the articles in the Microsoft Knowledge Base: