How to Open a New Document in Microsoft Office Word 2010. Do you want to open a new document in Microsoft Word 2010? Read on and you shall learn. Open up Microsoft Word 2010. Open Microsoft Word. If you have Windows, it’s in the ('Start' icon) menu in the Microsoft Office.
Opens the specified document and adds it to the Documents collection. Returns a Document object.
Syntax
expression.Open (FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument, OpenAndRepair, DocumentDirection, NoEncodingDialog)
expression Required. A variable that represents a Documents object.
Parameters
Return value
Document
Security
How to download acrobat reader for free. Important
Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code. For recommended best practices on how to do this, see Security notes for Office solution developers.
Example
This example opens MyDoc.doc as a read-only document.
This example opens Test.wp using the WordPerfect 6.x file converter.
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
-->
This topic shows how to use the classes in the Open XML SDK 2.5 forOffice to programmatically open a Word processing document from astream.
The following assembly directives are required to compile the code inthis topic.
When to Open a Document from a StreamOpen Document Format Download
If you have an application, such as a SharePoint application, that workswith documents using stream input/output, and you want to employ theOpen XML SDK 2.5 to work with one of the documents, this is designed tobe easy to do. This is particularly true if the document exists and youcan open it using the Open XML SDK 2.5. However, suppose the document isan open stream at the point in your code where you need to employ theSDK to work with it? That is the scenario for this topic. The samplemethod in the sample code accepts an open stream as a parameter and thenadds text to the document behind the stream using the Open XML SDK 2.5.
Creating a WordprocessingDocument Object
In the Open XML SDK, the WordprocessingDocument class represents aWord document package. To work with a Word document, first create aninstance of the WordprocessingDocumentclass from the document, and then work with that instance. When youcreate the instance from the document, you can then obtain access to themain document part that contains the text of the document. Every OpenXML package contains some number of parts. At a minimum, a WordProcessingDocument must contain a maindocument part that acts as a container for the main text of thedocument. The package can also contain additional parts. Notice that ina Word document, the text in the main document part is represented inthe package as XML using WordprocessingMLmarkup.
To create the class instance from the document call the Open(Stream, Boolean) method. Several Open methods are provided, each with a differentsignature. The sample code in this topic uses the Open method with a signature that requires twoparameters. The first parameter takes a handle to the stream from whichyou want to open the document. The second parameter is either true or false andrepresents whether the stream is opened for editing.
The following code example calls the Openmethod.
Structure of a WordProcessingML Document
The basic document structure of a WordProcessingML document consists of the document and bodyelements, followed by one or more block level elements such as p, which represents a paragraph. A paragraphcontains one or more r elements. The r stands for run, which is a region of text witha common set of properties, such as formatting. A run contains one ormore t elements. The t element contains a range of text. For example,the WordprocessingML markup for a document that contains only the text'Example text.' is shown in the following code example.
Using the Open XML SDK 2.5, you can create document structure andcontent using strongly-typed classes that correspond to WordprocessingMLelements. You can find these classes in the DocumentFormat.OpenXml.Wordprocessingnamespace. The following table lists the class names of the classes thatcorrespond to the document, body, p, r, and t elements.
How To Open Document In Wordpad
How the Sample Code Works
When you open the Word document package, you can add text to the maindocument part. To access the body of the main document part you assign areference to the existing document body, as shown in the following codesegment.
When you access to the body of the main document part, add text byadding instances of the Paragraph, Run, and Textclasses. This generates the required WordprocessingML markup. The following lines fromthe sample code add the paragraph, run, and text.
Sample Code
The example OpenAndAddToWordprocessingStream method shownhere can be used to open a Word document from an already open stream andappend some text using the Open XML SDK. You can call it by passing ahandle to an open stream as the first parameter and the text to add asthe second. For example, the following code example opens theWord13.docx file in the Public Documents folder and adds text to it.
How To Open A Docx Document In Word
Note
Notice that the OpenAddAddToWordprocessingStream method does not close the stream passed to it. The calling code must do that.
Following is the complete sample code in both C# and Visual Basic.
How To Open A Pdf Document In WordSee alsoComments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |