3

How do you open a word document in VB.NET. The document is a manual for the program.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
muckdog12
  • 51
  • 1
  • 2
  • 3

4 Answers4

11

You need to call Process.Start(documentPath).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    I didn't downvoted yours but for me the right answer is John Smith one. Your answer tell how to start any file associated to a program while the other answer really tell how to open a word document in VB.NET. – LogoS Sep 29 '16 at 23:37
  • @LogoS: No; that answer assumes that the user has Word, which may not be true. It's also much slower. – SLaks Sep 30 '16 at 00:14
  • Maybe the question is not well asked, he/she seems to wanted to open .DOC with some program to show it, not open it "IN VB.NET", in which case, maybe your answer fit. But your answer didn't work for me. I wanted to open .doc to work with it from VB (modify the content programatically), not to make it possible for the user to work with it. – LogoS Oct 06 '16 at 22:27
7

You open it by:

Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("C:\wordfile.docx")

Don't forget to use Imports Microsoft.Office.Interop.Word

jonsca
  • 10,218
  • 26
  • 54
  • 62
John Smith
  • 81
  • 1
  • 3
1

Use Process.Start to launch a Word document in the appropriate editor.

If you have access to the assemblies, you can use the Microsoft.Office.Interop.Word namespace to manipulate Word documents in code, though this is probably nowhere near as trivial as Excel interop, unless you're making very simple word documents.

Nick Bedford
  • 4,365
  • 30
  • 36
0

The Microsoft Web Browser Control can display ActiveX documents. This control can be placed onto a WinForms or WPF application

Microsoft Word is a ActiveX document provider. So you can load Microsoft Word documents into the Web Browser control. See this example for VB.Net 2005

You then have total control of the Microsoft Word child window. Load any document, re-size window, change visibility etc, you can even send control messages (macros)

Some other SO references:

Community
  • 1
  • 1
TFD
  • 23,890
  • 2
  • 34
  • 51