方法1﹕ Function IsOpen(sFile As String) As Boolean Dim fFile As Integer fFile = FreeFile() On Error GoTo ErrOpen Open sFile For Binary Lock Read Write As fFile Close fFile Exit Function ErrOpen: If Err.Number <> 70 Then Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext Else IsOpen = True End If End Function方法2: Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _ lpReOpenBuff As OFSTRUCT, _ ByVal wStyle As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Type OFSTRUCT cBytes As Byte fFixedDisk As Byte nErrCode As Integer Reserved1 As Integer Reserved2 As Integer szPathName As String * 128 End TypePrivate Const OF_SHARE_DENY_READ = &H30 Dim My As OFSTRUCTPublic Function IsUse(FileName As String) As Boolean Dim HFile As Long HFile = OpenFile(FileName, My, OF_SHARE_DENY_READ) If HFile = -1 Then IsUse = True Else IsUse = False CloseHandle HFile End If End Function
方法1﹕
Function IsOpen(sFile As String) As Boolean
Dim fFile As Integer
fFile = FreeFile()
On Error GoTo ErrOpen
Open sFile For Binary Lock Read Write As fFile
Close fFile
Exit Function
ErrOpen:
If Err.Number <> 70 Then
Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
Else
IsOpen = True
End If
End Function方法2:
Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName As String * 128
End TypePrivate Const OF_SHARE_DENY_READ = &H30
Dim My As OFSTRUCTPublic Function IsUse(FileName As String) As Boolean
Dim HFile As Long
HFile = OpenFile(FileName, My, OF_SHARE_DENY_READ)
If HFile = -1 Then
IsUse = True
Else
IsUse = False
CloseHandle HFile
End If
End Function
如果只是为了上传的话..不用判断应该也可行..复制一份到某某地方,然后传复制的这份就可以了..如果真要判断的话,还可以引用这个方法...>> 复制一份 >>删除原TXT (删不了表示打开,在这里设置错误返回值).>> 记得把复制的那份放到原来的地方>> 再传这份复制过来的那个..