Private Sub Form_Load() On Error Resume Next Dim objword As Word.Application Dim i As Integer Set objword = GetObject(, "Word.Application") If Err.Number <> 0 Then Set objword = New Word.Application End If If objword.Documents.Count = 0 Then MsgBox "没有文件被打开!" End If For i = 1 To objword.Documents.Count If objword.Documents(i).FullName = "D:\abc.doc" Then Exit For End If Next i If i > objword.Documents.Count Then MsgBox "该文件已经被打开了! " End If End Sub
On Error Resume Next
Dim objword As Word.Application
Dim i As Integer
Set objword = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set objword = New Word.Application
End If
If objword.Documents.Count = 0 Then
MsgBox "没有文件被打开!"
End If
For i = 1 To objword.Documents.Count
If objword.Documents(i).FullName = "D:\abc.doc" Then
Exit For
End If
Next i
If i > objword.Documents.Count Then
MsgBox "该文件已经被打开了! "
End If
End Sub