+ -
当前位置:首页 → 问答吧 → 我想知道特定路径下的文档有没有打开,要怎么做呢?

我想知道特定路径下的文档有没有打开,要怎么做呢?

时间:2011-02-10

来源:互联网

我想知道特定路径下的文档有没有打开,要怎么做呢?
写了个,不成功,大伙帮忙看看咯

附件

看看特定路径下的文档有没有打开.rar(8.41 KB)

2011-2-10 22:41, 下载次数: 2

作者: inadequate   发布时间: 2011-02-10

看看是不是你想要的。


'声明必要的 API:
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
                    ByVal lpWindowName As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


Sub ple()
    Dim myWd As Object, oDoc As Object
    On Error Resume Next
    Set myWd = GetObject(, "Word.Application")
      Dim hWnd As Long
    '如果 Word在运行,则该 API 调用将返回其句柄。
    hWnd = FindWindow("OpusApp", 0)
    If hWnd <> 0 Then    '0 表示没有 Word在运行。

    myDocName = ThisWorkbook.Path & "\my.doc"
    For Each oDoc In myWd.documents
        If UCase(oDoc.FullName) = UCase(myDocName) Then blnFound = True: Exit For
    Next
    If blnFound = True Then
        MsgBox "目标文档已经打开!", vbInformation, "Microsoft Word"
    Else
        MsgBox "目标文档没有打开!", vbInformation, "Microsoft Word"
    End If
    End If
End Sub

[ 本帖最后由 wl9643 于 2011-2-10 23:08 编辑 ]

作者: wl9643   发布时间: 2011-02-10

晕,这么复杂呀,还要API。有不要API的吗?

作者: inadequate   发布时间: 2011-02-11