I am trying to convert all ~200 xlsx files txt using the below vb. In each .xlsx file there is a worksheet with "analysis" in the name that I am trying to copy to Const Filepath So in that directory there will be 200 txt files all from the "analysis" sheet in the .xlsx files. The vb runs but nothing happens and I need some expert help getting this to work. I have been trying for days with no luck. Thank you .
VB
Private Sub CommandButton1_Click()
Dim fName As String, fPath As String, wb As Workbook
Const Filepath As String = "C:\Users\cmccabe\Desktop\folder"
fPath = "C:\Users\cmccabe\Desktop\epilepsy\"
fName = Dir(fPath & "*analysis*.xlsx")
Do While fName <> ""
Set wb = Workbooks.Open(fPath & fName)
wb.SaveAs Left(fName, Len(fName) - 5) & ".txt", FileFormat:=xlText
fName = Dir
Filename = Filepath & "\" & Left(oFile, InStrRev(oFile, ".")) & "txt"
Open Filename For Output Access Write As #1
Print #1, Text
Close #1
Loop
End Sub