title: copy Excel data into text file
body: <p>I have done the below code to copy Excel cell data to a txt file. I have to create one text file each for each cell in an Excel. like if I have n cells data in Excel I need n txt files. </p>
  
  <pre><code>Sub ExportToNotepad()
    Dim wsData As Variant
    Dim myFileName As String
    Dim FN As Integer
    Dim p As Integer, q As Integer
    Dim sPath As String
    Dim myString As String
    Dim lastrow As Long, lastcolumn As Long
  
    Dim wb As Workbook
    Set wb = Workbooks.Open("C:\Users\sc00359878\Desktop\sample_excel.xlsx")
  
    lastrow = wb.Sheets("sheet1").Range("B" &amp; Rows.Count).End(xlUp).Row
    lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    sPath = "C:\Users\sc00359878\Desktop\output\"
  
    For p = 1 To lastrow
      wsData = ActiveSheet.Range("B" &amp; p).Value
  
      If wsData = "" Then Exit Sub
      myFileName = "sMove.txt"
      myFileName = sPath &amp; myFileName
  
      FN = FreeFile
      Open myFileName For Output As #FN
      Print #FN, wsData
      Close #FN
  
      myString = ""
    Next p
  End Sub
  </code></pre>
  
  <p>I'm getting the below error when I tried running it.</p>
  
  <p><a href="https://i.stack.imgur.com/1ZMtf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1ZMtf.png" alt="enter image description here"></a></p>