title: Is it possible to copy the contents of the Immediate window in Excel VBA?
body: <p><strong>Question</strong></p>
  
  <p>I would like to know whether it is possible to copy or extract the contents of the Immediate window in Excel VBA, so I can store it somewhere. I already know you can copy and paste from the window manually, I am interested in whether it is possible to do it with code (preferably in VBA itself).</p>
  
  <p><strong>Explanation</strong></p>
  
  <p>Questions similar to this have been asked a few times on SO (e.g. <a href="https://stackoverflow.com/questions/42996281/excel-vba-print-results-of-immediate-window-in-a-cells">this</a> and <a href="https://stackoverflow.com/questions/7015486/write-contents-of-immediate-window-to-a-text-file">this</a>), no-one has given a definitive answer and I was unable to find one from a quick search. Most of the time, answers respond asking why anyone would want to do that, and give ways to get around it in the circumstances provided in the question (e.g. how to output messages to a file or cell range). Given this, I have thought of a couple of example scenarios where someone might want to do this and cannot (easily) get around it.</p>
  
  <p><strong>Example scenarios</strong></p>
  
  <p>A) I am developing a large workbook including a large set of macros, debugging as I go. This includes using <code>debug.print</code> statements and directly querying in the Immediate window, e.g. <code>? myVar</code>. At the end of the session, I would like to be able to automatically copy the contents of the immediate window into a log file, so I know what happened during my debug session afterwards. This could, for example, make use of the <code>Workbook_BeforeClose</code> event procedure.</p>
  
  <p>B) I am working with two workbooks that contain VBA projects - one I can't edit, another that I can and am working on. The one I can't edit outputs debug information to the immediate window via <code>debug.print</code> that I would like to store somewhere (but I don't really care where).</p>
  
  <p><strong>Disclaimer</strong></p>
  
  <p>I ask this question purely out of curiosity. I suspect I already know the answer (it's not possible to do this), but I am not sure.</p>