If Dir("C:\TEST.XLS") = Empty Then
MsgBox "文件不存在。"
End If
On Error Resume Next
Set B = Workbooks("TEST.XLS")
If Err.Number = 0 Then
MsgBox testfile & "檔案已開啟"
End If作者: kimbal 時間: 2011-7-27 22:43
Sub test()
Dim result As Integer
result = FileLocked("C:\TEST.XLS")
Select Case result
Case Is = 76
MsgBox ("路徑不存在。")
Case Is = 75
MsgBox ("文件不存在。")
Case Is = 70
MsgBox ("檔案已開啟")
Case Is = 0
MsgBox ("檔案正常")
Case Else
MsgBox ("檔案有不明問題")
End Select
End Sub
Function FileLocked(strFileName As String) As Integer
On Error Resume Next
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
FileLocked = Err.Number
If Err.Number <> 0 Then
Err.Clear
End If
End Function作者: GBKEE 時間: 2011-7-28 10:01
Sub Ex()
Dim F As Boolean
F = CreateObject("Scripting.FileSystemObject").FileExists("D:\TEST.XLS")