假定c盘下有一EXCEL文件a.xls,并已经打开,应该用什么语句来判断文件是否已经打开呢?请各位大虾指教。

解决方案 »

  1.   

    Option ExplicitConst OFS_MAXPATHNAME = 128
    Const OF_SHARE_DENY_READ = &H30Private Type OFSTRUCT
            cBytes As Byte
            fFixedDisk As Byte
            nErrCode As Integer
            Reserved1 As Integer
            Reserved2 As Integer
            szPathName(OFS_MAXPATHNAME) As Byte
    End TypePrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
    Private OF As OFSTRUCT
    Private Sub Form_Load()
    Dim hFile As Long
    hFile = OpenFile("c:\a.xls", OF, OF_SHARE_DENY_READ)
    If hFile = -1 Then
        If Err.LastDllError = 32 Then
            MsgBox "文件已打开"
        Else
            MsgBox "异常错误:" & Err.LastDllError
        End If
    Else
        MsgBox "文件未打开"
        CloseHandle hFile
    End IfEnd Sub
      

  2.   

    http://www.microsoft.com/china/msdn/archives/technic/tips/msproject.asp