R: #000000">_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare id="_148_1353_Closed_Text" >Function lClose()Function lClose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
'' 判斷某文件是否在使用中
Public Function IsFileAlreadyOpen()Function IsFileAlreadyOpen(ByVal FileName As String>) As Boolean
Dim hFile As Long
Dim lastErr As Long
hFile = -1 '' 初始化文件句柄.
lastErr = 0
hFile = lOpen(FileName, &H10)
If hFile = -1 Then '' 文件是否能正確打開並可共享
lastErr = Err.LastDllError
Else
lClose(hFile)
End If
IsFileAlreadyOpen = (hFile = -1) And (lastErr = 32)
End Function
Private olid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">Sub Command1_Click()Sub Command1_Click()
Dim strFileName As String
strFileName = "d:\050304_chengji.xls" '' 你的文件
If IsFileAlreadyOpen(strFileName) Then
MsgBox("指定文件已打開")
le="COLOR: #0000ff">Else
MsgBox("指定文件未打開")
End If
End Sub 今天作程序的時候發現的問題,上網搜了一下發現這個程序不錯,於是就留在這裡共大家參考,希望對大家有所幫助,與人方便,與己更方便!