Hi,
I would like to convert multiple text files to excel files respectively..
I have nearly 800 text files which needs to be converted to excel files individually..
Can any one guide me please
Hi,
I would like to convert multiple text files to excel files respectively..
I have nearly 800 text files which needs to be converted to excel files individually..
Can any one guide me please
1) Turn on your macro recorder.
2) Open one of your text files and convert it/save it as XLS
3) Open a second text file and convert it/save it as XLS
4) Turn off the macro recorder
5) Press Alt-F8 to open the macro list
6) Click once on your recorded macro and select EDIT
7) Copy that code into memory
8) In the forum QUICK REPLY box below, click GO ADVANCED
9) Click the # icon
10) Paste in the code you copied between those code tags
We'll take a look and offer replacement code that will open/convert all the files in that folder for you based on what we see in your recorded macro.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
hello sir, i have to convert 1200 text files to individual excel files. i have done according to your post and sending you the macros code. please look at it and let me know for further processing.
![]()
Sub convert_text_files() ' ' convert_text_files Macro ' ' ChDir "C:\Users\harsha\Desktop\data" Workbooks.OpenText Filename:= _ "C:\Users\harsha\Desktop\data\RXN_LT06375LG066875.txt", Origin:=437, _ StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _ Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _ , 1), Array(4, 1)), TrailingMinusNumbers:=True ActiveWorkbook.SaveAs Filename:= _ "C:\Users\harsha\Desktop\data\RXN_LT06375LG066875.xls", FileFormat:=xlExcel8 _ , Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ CreateBackup:=False ActiveWindow.Close Workbooks.OpenText Filename:= _ "C:\Users\harsha\Desktop\data\RXN_LT06375LG067375.txt", Origin:=437, _ StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _ Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _ , 1), Array(4, 1)), TrailingMinusNumbers:=True ActiveWorkbook.Save ActiveWorkbook.SaveAs Filename:= _ "C:\Users\harsha\Desktop\data\RXN_LT06375LG067375.xls", FileFormat:=xlExcel8 _ , Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ CreateBackup:=False ActiveWindow.Close End Sub
Last edited by JBeaucaire; 07-07-2015 at 10:40 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.
Normally it is against the rules to HIJACK someone else's thread with a question of your own. In this rare instance the OP has abandoned the thread, so we'll let you take it so as to complete the usefulness of the thread's existence. But be warned, as this is your first post I suspect you might nit have read the rules you agreed to abide. Take a moment and read them now, there's a link to the Forum Rules in the menu bar above.
============
Based on your sample, this should process all the files in the given fPATH:
![]()
Option Explicit Sub Convert_Text_Files() Dim fPATH As String, fNAME As String, wb As Workbook, CNT As Long fPATH = "C:\Users\harsha\Desktop\data\" 'remember the final \ in this path string fNAME = Dir(fPATH & "RXN*.txt") 'get the first RXN text filename from fPATH Application.ScreenUpdating = False 'speed up macro Do While Len(fNAME) > 0 'loop through one file at a time til all done CNT = CNT + 1 'keep count of how many files converted 'open the found file in Excel Workbooks.OpenText Filename:=fPATH & fNAME, Origin:=437, _ StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _ Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _ Array(3, 1), Array(4, 1)), TrailingMinusNumbers:=True Set wb = ActiveWorkbook 'save in Excel format wb.SaveAs Filename:=fPATH & Replace(fNAME, "*.txt", ".xls"), FileFormat:=xlExcel8, _ Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False wb.Close False 'close the new workbook fNAME = Dir 'get the next filename Loop Application.ScreenUpdating = True MsgBox "Done, a total of " & CNT & " text files were converted." End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks