Sub SetAttribue()
Dim strFile As String
strFile = "c:\temp\test.xlsx"
If Not IsWorkBookOpen(strFile) Then
SetAttr strFile, vbReadOnly ' 不太懂這邊的意思
MsgBox "file now readonly"
Else
MsgBox "File is already open"
End If
End Sub
Function IsWorkBookOpen(FileName As String) As Boolean
Dim ff As Long
Dim ErrNo As Long
On Error Resume Next
ff = FreeFile() ' 不懂語法
Open FileName For Input Lock Read As #ff ' 不懂 #ff 意思
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function作者: sghsgh1111 時間: 2015-4-3 23:16
Sub SetAttribue()
Dim strFile As String
strFile = "c:\temp\test.xlsx"
If Not IsWorkBookOpen(strFile) Then
SetAttr strFile, vbReadOnly ' 不太懂這邊的意思
MsgBox "file now readonly"
Else
MsgBox "File is already open"
End If
End Sub
Function IsWorkBookOpen(FileName As String) As Boolean
Dim ff As Long
Dim ErrNo As Long
On Error Resume Next
ff = FreeFile() ' 不懂語法
Open FileName For Input Lock Read As #ff ' 不懂 #ff 意思
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select