title: VBA: Could not write cell values to text file
body: <p>I have an existing excel worksheet with data that is something like this:</p>
  
  <pre><code>Col A  Col B        Col C
  123    17/1/1993    ABC
  124    18/1/1993    DEF
  125    19/1/1993    AAD
  126    20/1/1993    AIG
  127    21/1/1993    GBI
  </code></pre>
  
  <p>I want to write the data into a tab-delimited text file. With the following code, the text file created does not contain the values in the cells, although the tabs are written to the text file.</p>
  
  <pre><code>Sub writetotext()
      Dim lastrow As Long
      Dim lastcol As Long
      Dim i As Integer, j As Integer
      Dim celldata As String
      Dim fname As String
      Dim fso As Object
  
      Dim ws As Worksheet
  
      fname = ThisWorkbook.Path &amp; "\textoutput.txt"
      lastrow = ThisWorkbook.Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
      lastcol =        ThisWorkbook.Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Column
      Set ws = ThisWorkbook.Sheets(1)
  
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set objFile = fso.CreateTextFile(fname)
  
      For i = 1 To lastrow
          For j = 1 To lastcol
              If j = lastcol Then
                  celldata = celldata + ActiveCell(i, j).Value
              Else
                  celldata = celldata + ActiveCell(i, j).Value + vbTab
              End If
          Next j
          objFile.writeline celldata
          celldata = ""
      Next i
  
      objFile.Close
  
  End Sub
  </code></pre>
  
  <p>Seems like ActiveCell(i, j).Value does not work, but I don't know how to rectify this problem. I'm using Excel 2010</p>