title: Function to direct debug to text file
body: <p>I would like to write a function to would allow me to use <code>Print #Debug, "text"</code> throughout my future modules to collect debug statements.</p>
  
  <pre><code>Sub output_debug()
  Dim WshShell As Object
  Dim Desktop As String
  Dim Debug As Integer
  
  Debug = FreeFile()
  
  Set WshShell = CreateObject("WScript.shell")
  Desktop = WshShell.specialfolders("Desktop")
  
  Open Desktop &amp; "\VBA_output.txt" For Output As #Debug
  Print #Debug, "test"
  
  Close #Debug
  
  End Sub
  </code></pre>
  
  <p>How can I move from the above, to defining a function that would allow me to use <code>call output_debug()</code> in a module so all my <code>Print #Debug,</code> would print to that file ? I would imagine I need to create another function called <code>close_output()</code> that has <code>close #Debug</code></p>