title | description | ms.date | ms.topic | dev_langs | helpviewer_keywords | author | ms.author | manager | ms.subservice | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Programmatically open existing documents |
Open an existing Microsoft Word document by using a fully qualified path and file name programmatically from Visual Basic or C# in Visual Studio. |
02/02/2017 |
how-to |
|
|
John-Hart |
johnhart |
mijacobs |
office-development |
The xref:Microsoft.Office.Interop.Word.Documents.Open%2A method opens the existing Microsoft Office Word document specified by a fully qualified path and file name. This method returns a xref:Microsoft.Office.Interop.Word.Document that represents the opened document.
[!INCLUDEappliesto_wdalldocapp]
-
Call the xref:Microsoft.Office.Interop.Word.Documents.Open%2A method of the xref:Microsoft.Office.Interop.Word.Documents collection and supply a path to the document.
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationCS/ThisDocument.cs" id="Snippet5":::
-
Call the xref:Microsoft.Office.Interop.Word.Documents.Open%2A method, supply a path to the document, and set the ReadOnly argument to True in the method call.
:::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationCS/ThisDocument.cs" id="Snippet6":::
This code example requires the following:
- A document named NewDocument.doc must exist in a directory named Test on drive C.