VB.NET操作Word之1,在project eferences 中加入microsoft word 11.0 object library (2003)
一、启动打开Word文档
<div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; "> Dim oWord As Word.Application</span></div><div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; "> Dim oDoc As Word.Document</span></div><div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; "> oWord = New Word.Application</span></div><div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; "> oWord.Visible = False</span></div><div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; "><span style="white-space:pre"> oDoc = oWord.Documents.Open(FileName:=FilePath)</span></span></div>
二、关闭word文档
<div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; ">oWord.Quit()</span></div><div style="text-align: left;"><span style="background-color: rgb(248, 248, 248); font-family: 宋体; ">oWord = Nothing</span></div>
三、需要导入的内容
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word.WdColor