1个回答
展开全部
判断指定的WORD文档是否被打开的函数代码如下:
Function WordDocIsOpen(ByVal strDocName As String) As Boolean
Dim objWordApp As Object
Dim objWordDoc As Object
On Error Resume Next '此句不能少
strDocName = UCase(strDocName)
Set objWordApp = GetObject(, "Word.Application")
For Each objWordDoc In objWordApp.Documents
If UCase(objWordDoc.FullName) = strDocName Then
WordDocIsOpen = True
Exit For
End If
Next
Set objWordDoc = Nothing
Set objWordApp = Nothing
End Function
调用代码:
Private Sub main()
If WordDocIsOpen("e:/1.doc") Then
MsgBox "该文档已被打开"
Else
MsgBox "该文档未被打开"
End If
End Sub
Function WordDocIsOpen(ByVal strDocName As String) As Boolean
Dim objWordApp As Object
Dim objWordDoc As Object
On Error Resume Next '此句不能少
strDocName = UCase(strDocName)
Set objWordApp = GetObject(, "Word.Application")
For Each objWordDoc In objWordApp.Documents
If UCase(objWordDoc.FullName) = strDocName Then
WordDocIsOpen = True
Exit For
End If
Next
Set objWordDoc = Nothing
Set objWordApp = Nothing
End Function
调用代码:
Private Sub main()
If WordDocIsOpen("e:/1.doc") Then
MsgBox "该文档已被打开"
Else
MsgBox "该文档未被打开"
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询