我想做到,用VB打开一个WORD,当再要打开的时候提示他已经被打开了

解决方案 »

  1.   

    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