Dim WordApp As New Word.Application
Dim WordDocument As Word.Document
'获取路径
Dim STR As String
STR = OpenPath()
'判断路径是否为空
If STR <> "" Then
WordDocument = WordApp.Documents.Open(STR, , True)
'激活文档
WordDocument.Activate()
'显示文档
WordApp.Visible = True
Else
MessageBox.Show("本次操作取消")
WordApp.Quit()
End If
End Sub
'获取路径过程
Function OpenPath() As String
Dim STR As String
STR = ""
Dim OpenFile As New OpenFileDialog()
With OpenFile
.Filter = "WORD (*.doc)|*.doc"
.FilterIndex = 1
.Title = "选择WORD文件"
End With
If OpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
STR = OpenFile.FileName
End If
Return STR
End Function