'打开一个Word文档 'FileName为文档的路径文件名,若为""表示打开空文档 '函数返回1表示打开成功,返回0表示失败 Public Function OpenDocument(FileName As String) As Integer Dim oWord As Word.Application Dim oDocument As Word.Document Dim nRet As Integer
On Error GoTo ErrOpen
Set oWord = New Word.Application
If FileName = "" Then Set oDocument = oWord.Documents.Add Else Set oDocument = oWord.Documents.Open(FileName) End If
oWord.Visible = True
OpenDocument = 1 GoTo ExitOpen
ErrOpen: OpenDocument = 0ExitOpen: Set oDocument = Nothing Set oWord = Nothing End Function
'FileName为文档的路径文件名,若为""表示打开空文档
'函数返回1表示打开成功,返回0表示失败
Public Function OpenDocument(FileName As String) As Integer
Dim oWord As Word.Application
Dim oDocument As Word.Document
Dim nRet As Integer
On Error GoTo ErrOpen
Set oWord = New Word.Application
If FileName = "" Then
Set oDocument = oWord.Documents.Add
Else
Set oDocument = oWord.Documents.Open(FileName)
End If
oWord.Visible = True
OpenDocument = 1
GoTo ExitOpen
ErrOpen:
OpenDocument = 0ExitOpen:
Set oDocument = Nothing
Set oWord = Nothing
End Function