您的位置:首页 > 编程语言 > VB

VBA 判断Word进程是否存在和当前word文档是否打开

2008-12-09 08:15 507 查看
最近写了点关于word的程序,要判断word程序是否存在。现提供给大家分享(vb6):

首先要引用microsoft word 11.0 object library(即系统安装了office 2003),具体代码如下

Private Function WordisExist(ByVal FilePath As String, ByVal DocName As String) As Integer
If Dir(FilePath) = "" Then
WordisExist = 3
' Debug.Print "Word文件不存在"
Exit Function
End If
' 搜索word文档是否已经打开
On Error GoTo ERROR0
For Each Doc In Word.Application.Documents
If Doc.Name = DocName Then
Found = True
Exit For
End If
Next
If Found Then
' MsgBox ("要打开的word文档已经打开")
WordisExist = 1
Exit Function
End If
ERROR0:
If Err = 0 Then
' MsgBox "将所用的word文档和进程关闭"
WordisExist = 2
Exit Function
Else
Err.Clear
End If
WordisExist = 0
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: