title: Problom With VBA code throw an “user defined type not defined” error
body: <p>I cannot figure out why the following code is throwing a compile error with the message "user defined type not defined". It is highlighting Set fso = FileSystemObject</p>
  
  <pre><code>Sub S()     
  Dim fso As FileSystemObject
      Dim ts As TextStream
      Dim i As Integer
      Dim myCell As Range
  
      Set fso = FileSystemObject
  
      For i = 0 To TotalColumnNumber
         ' last argument, True, says to create the text file if it doesnt exist, which is
         ' good for us in this case
         Set ts = fso.OpenTextFile("column_" &amp; i, ForWriting, True)
  
         ' set mycell to the first cell in the ith column
         Set myCell = SheetName.Cells(1, i)
  
         ' continue looping down the column until you reach a blank cell
         ' writing each cell value as you go
         Do Until myCell.Value = ""
             ts.writeline myCell.Value
             Set myCell = myCell.Offset(1, 0)
         Loop
  
         ts.Close
      Next
  
      Set ts = Nothing
      Set fso = Nothing
  
  
      End Sub
  </code></pre>
  
  <p>thanks</p>