Automate microsoft word to create a new document




















Add 'Insert a paragraph at the beginning of the document. Add oPara1. InsertParagraphAfter 'Insert a paragraph at the end of the document. Add oDoc. Range oPara2. InsertParagraphAfter 'Insert another paragraph. Range oPara3.

Now here is a table:" oPara3. InsertParagraphAfter 'Insert a 3 x 5 table, fill it with data, and make the first row 'bold and italic. Range, 3, 5 oTable. Cell r, c. Item 1. Range oPara4. InsertParagraphBefore oPara4. InsertParagraphAfter 'Insert a 5 x 2 table, fill it with data, and change the column widths. Range, 5, 2 oTable. Item 2. InchesToPoints 3 'Keep inserting text. When you get to 7 inches from top of the 'document, insert a hard page break.

InchesToPoints 7 oDoc. Range oRng. InsertAfter "A line of text" oRng. Information Word. Collapse Word. InsertBreak Word. InsertAfter "We're now on page 2. 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 run time, as follows:. For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:.

Microsoft Office Development with Visual Studio. Once you have enabled that tab, under the Controls section you can add any number of text content controls into your document. Use the control Properties to give the control a friendly name that you will use in the flow.

Once you are done creating your Word document, save it to one of the above document library locations. NET, follow these steps:. On the File menu, click New, and then click Project. Form1 is created by default.

Scroll to the top of the code window. Add the following line to the end of the list of using directives:. After the code completes, examine the document that was created for you. The document contains two pages of formatted paragraphs, tables, and a chart.



0コメント

  • 1000 / 1000