你好:
這個網站是在台灣的
貼出網址中的其中一個方法
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" ( _
ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lClose Lib "kernel32" Alias "_lclose" ( _
ByVal hFile As Long) As Long
Private Const OF_SHARE_EXCLUSIVE = &H10
Private Function IsFileOpen(rFile As String) As Boolean
Dim errnum As Long
Dim lastErr As Long
errnum = -1
hdlFile = lOpen(rFile, OF_SHARE_EXCLUSIVE)
If hdlFile = -1 Then
lastErr = Err.LastDllError
Else
lClose (hdlFile)
End If
IsFileOpen = (hdlFile = -1) And (lastErr = 32)
End Function
範例:判斷 C:\test\test.xls 檔案是否存在
Sub test()
Dim rPath As String
rPath = "C:\test\test.xls"
MsgBox "檔案" & rPath & IIf(IsFileOpen(rPath), "已開啟", "未開啟")
End Sub
--
天行健,君子以自強不息
地勢坤,君子以厚德載物
http://www.vba.com.tw/plog/
"Limking" 來函:
Post by Limking是不是另一種方法,好可惜,打不開這個網頁,可能是被大陸封殺了吧
"chijanzen" 來函:
Post by chijanzen請參考範例
http://www.vba.com.tw/plog/post/1/29
--
天行健,君子以自強不息
地勢坤,君子以厚德載物
http://www.vba.com.tw/plog/
"Limking" 來函:
Post by Limking請問,在VBA中,怎樣知道某個workbook是否已經開啟,謝謝!