title: Writing to the files simultaneously in Excel Macro
body: <p>I am preparing excel macro to read data from Input file and output it to two different file depending on condition.</p>
  
  <p>Code Snippet as below</p>
  
  <pre><code>   fileName1="test1.txt"
     fileName2="test2.txt"
     file1 = FreeFile()
     file2 = FreeFile()
  
     Open fileName1 For Output As file1
     Open fileName2 For Output As file2
  
     If Condition1=true Then
         sWrite1="Write to file 1"
         print #file1,sWrite1
     Else
         sWrite2="Write to file 2"
         print #file2,sWrite2
     End If
  
     Close #file1
     Close #file2
  </code></pre>
  
  <p>Expected output is "Write to file 1" should go to file1 
  and "Write to file 2" should be to file2.</p>
  
  <p>But after running the macro ,
  both "Write to file 1" and "Write to file 2" were written to file2 
  and file1 is empty.</p>
  
  <p>Can anyone please help me on how to write simultaneously to two files.</p>