Hello!
I am trying to use this lines of code for converting xls files in one folder to tabformated txt files and the originals are saved in "Imported" folder. I can not make it to work, I use this line of codes from another project and tried to reuse it for this purpouse with no luck!
I have comment out two lines that is not needed for this task!
Any advices would be great!
Sub XLS_to_TEXT()
'Opens ALL XLS files in a folder, then saves as tabformated txt
'Moves imported files into an IMPORTED folder in the same directory
Dim fName As String, OldDir As String, Cnt As Long
Dim fSave As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'memorizes the users current working path
OldDir = CurDir
'Path with the files to convert, create the imported folder if needed
ChDir "C:\my_folder\xls_files"
On Error Resume Next
MkDir CurDir & "\Imported\"
On Error GoTo 0
'Create a list of the files in that folder
fName = Dir("*.xls")
'Open files one at a time to process them
Do While Len(fName) > 0
'Open file
Workbooks.Open fName
'your code here
'Call SKV_to_Text2 OBS not needed
'Save to same directory as Excel file with same name
'fSave = Trim(Left(fName, InStr(fName, "_") - 1)) OBS not needed
ActiveWorkbook.SaveAs Filename:=fSave, FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close False
Name fName As "Imported\" & fName
Cnt = Cnt + 1
'Get next filename
fName = Dir
Loop
MsgBox "Complete, " & Cnt & " files were processed"
ChDir OldDir 'restores users original working path
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Bookmarks