Visual basic code to open a word file


















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. Contributions by Lori B. Turner, Microsoft Corporation. Skip to main content. This browser is no longer supported.

Download Microsoft Edge More info. 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. Here's my chart:" oRng. InsertParagraphAfter 'Insert a chart and change the chart.

Object oChart. Update oChart. Quit 'If desired, you can proceed from here using the Microsoft Graph 'Object model on the oChart object to make additional changes to the 'chart. InchesToPoints 6. InchesToPoints 3. InsertParagraphAfter oRng. Close this form. Close End Sub Add the following code to the top of Form1.

Word Press F5 to build and run the program. Use a template 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 Automation, you can create a new document based on your template with code such as the following: oWord. Item "MyBookmark". Need more help? Expand your skills. This browser is no longer supported. Download Microsoft Edge More info.

Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No. Any additional feedback? Important Avoid using hard-coded passwords in your applications. In this article. True to display the Convert File dialog box if the file isn't in Microsoft Word format.

True to open the document as read-only. This argument doesn't override the read-only recommended setting on a saved document.

True to add the file name to the list of recently used files at the bottom of the File menu. Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file.



0コメント

  • 1000 / 1000