title: How to make an external log using Excel VBA?
body: <p>The code has been updated to reference the changes below.</p>
  
  <p>This log system create an external document for Excel called Log.txt, it will create a line in the log.txt file that looks like this: </p>
  
  <blockquote>
    <p>11:27:20 AM Matthew Ridge changed cell $N$55 from ss to</p>
  </blockquote>
  
  <p>This will not tell you if someone entered a new line of code into the sheet, but if the code demands an answer, it will tell you what cell that answer is in. This codes below should work for both Mac and PC systems combined. If people find it doesn't please say.</p>
  
  <p>This code was created with the help of people here, and other forms, so I can't take sole proprietorship of the document, but I can take ownership of the concept. So thanks to those who helped, without this there now wouldn't be a viable logging system for Excel in my opinion ;)</p>
  
  <p>BTW, before anyone freaks out and asks where does this code go, it isn't obvious to the general/new end user. You need to go to the <strong><a href="http://msdn.microsoft.com/en-us/library/bb608625.aspx" rel="noreferrer">Developer Tab</a></strong> open it up, click on Visual Basic, and when the new window opens look for Microsoft Excel Object; under that folder should be your workbook. You can either put it under ThisWorkbook or inside any of the sheets by double clicking on the sheet you want the code to be in. </p>
  
  <p>Once the sheet is open on the right panel, you will see Option Explicit, if you don't it is best if you activate it by making sure the <strong>Require Variable Declaration</strong> is checked. This is found at the Visual Basic window again, and follow this path: </p>
  
  <p><strong>Tools</strong>-> <strong>Options</strong> -> <strong>Editor</strong>. </p>
  
  <p>If it is checked then you have no worry, if not then you check it. Option Explicit is a good thing for you code, it forces you to declare variables, which is a good practice to begin with.</p>
  
  <p>After it is verified, you can copy the code below to either paste it in your Workbook, or a specific sheet depending on your needs.</p>
  
  <h2>Version 2.01</h2>
  
  <pre><code>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 &amp; Application.PathSeparator &amp; "Log.txt"
  
   On Error Resume Next ' Turn on error handling
      If Target.Value &lt;&gt; 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 &amp; Application.UserName &amp; " changed cell " &amp; Target.Address _
          &amp; " from " &amp; PreviousValue &amp; " to " &amp; 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
  </code></pre>
  
  <p>As time goes by, I will attempt to update this code to add more features to it as I deem fit. </p>
  
  <p>Again thanks to all that helped, it is greatly appreciated to make this possible.</p>