Private Sub Workbook_Open()
Dim Path As String
Path = ThisWorkbook.Path & "\user.txt"
If Not ActiveWorkbook.ReadOnly Then '読み取り専用でない場合
Dim objNetWork As Object
Set objNetWork = CreateObject("WScript.Network")
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
With FSO.CreateTextFile(Path)
.WriteLine objNetWork.UserName
.Close
End With
Set objNetWork = Nothing
Set FSO = Nothing
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'***********************************************
' ファイルを閉じる際テキストファイル削除
'
'***********************************************
Dim Path As String
Path = ThisWorkbook.Path & "\user.txt"
If Not ActiveWorkbook.ReadOnly And Dir(Path) <> "" Then
Kill Path
End If
End Sub
'読み取り専用の場合
Dim Path As String
Path = ThisWorkbook.Path & "\user.txt"
If Dir(Path) <> "" Then
Open Path For Input As #1
Dim buf As String
Line Input #1, buf
MsgBox "ユーザー:" & buf & "が使用中"
Close #1
End If