これはユニバーサルログシステムであり、ここと私自身が作成したものです。私はそれをかなり誇りに思っています...私は2つの問題に直面しています...誰かが解決策を手伝ってくれるならそれは素晴らしいことです。
コードは次のとおりです。
Option Explicit
Dim PreviousValue
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sLogFileName As String, nFileNum As Long, sLogMessage As String
sLogFileName = ThisWorkbook.path & Application.PathSeparator & "Log.txt"
On Error Resume Next ' Turn on error handling
If Target.Value <> PreviousValue Then
' Check if we have an error
If Err.Number = 13 Then
PreviousValue = 0
End If
' Turn off error handling
On Error GoTo 0
sLogMessage = Now & Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value
nFileNum = FreeFile ' next file number
Open sLogFileName For Append As #nFileNum ' create the file if it doesn't exist
Print #nFileNum, sLogMessage ' append information
Close #nFileNum ' close the file
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target(1).Value
End Sub
ここに2つの問題があります。
- 複数のセルが選択され、書き込もうとすると、スクリプトはエラーになります。
- 誰かがセルを編集して空白のままにすると、
8/30/2012 1:45:01 PM Matthew Ridge changed cell $K$3 from Test to
代わりに表示されます8/30/2012 1:45:01 PM Matthew Ridge changed cell $K$3 from Test to Blank or Empty