Opening multiple text files

Santig14

New Member
Joined
Mar 7, 2020
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Following from this thread: Repeating Macro On Multiple Files In Order

Hi All! I think my level its quite bellow Chris before writting this post! ha. Even thow I think I could manage the code that you had gently provide. The thing is, the text files that I want to open are written with a same pattern, but I dont know if I can open all using the same code. Should I write it down every time?

The main idea is to run the following with all the files from the folder:

Workbooks.OpenText Filename:= _
"C:\U***s\G*****N\D*****ads\A****a\files\yyyymmdd.DAT", _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:= _
Array(Array(0, 1), Array(7, 1), Array(51, 1), Array(75, 1), Array(85, 1), Array(101, 1), _
Array(110, 1), Array(118, 1)), TrailingMinusNumbers:=True
Range("A1").Select

Hope you can help me, (pleasse!!!!)

Thanks a lot!

Santi.
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Santi. Please post an example of your file names and also some of the data contained therein.
 
Upvote 0
Hi there!
I´ve attached the (a) file name exaples (and the route to the containing folder) and (b) the data conintained on every file.

I was thinking on (i) rename the data files into a normalize structure such as (yyyymm) and (ii) put al the files at the same location (there are a folder by year). Also I have the detailed stucture of the data, so I can sparete it on the propper fields.

Hope it could be usefull for you,
Thanks!


1583679505943.png


1583679577698.png
 
Upvote 0
Santi, I looked at Chris' code to get a better understanding of what you are trying to accomplish.
Are you wishing to:
1. create a new workbook for each of your text files?
2. import multiple text files within a single worksheet?
3. or import each text file into it's own worksheet within the same workbook?
 
Upvote 0
Hi Dataluver!
Option 1 is the one that suits the better. Mostly because there are 72 different text files. So a single workbook it could be impossible to manege.
 
Upvote 0
Chris is about, so I sent him a message. It seems that his code with a bit of modification would work for you.
 
Upvote 0
No news from John. We'll start with this, but we'll likely have to go back and forth a few times to get it right.

VBA Code:
Sub Example()
    TextFilesToWB "path of text files here", _
      Array(Array(0, 1), Array(7, 1), Array(51, 1), Array(75, 1), Array(85, 1), Array(101, 1), Array(110, 1), Array(118, 1)), _
      "path of new workbooks here"
End Sub

Sub TextFilesToWB(rootPath, struct, saveTo)
    Dim fso, f
   
    Application.ScreenUpdating = False
    For Each f In CreateObject("scripting.filesystemobject").GetFolder(rootPath).Files
        Workbooks.OpenText f.Path, DataType:=xlFixedWidth, FieldInfo:=struct
        ActiveWorkbook.SaveAs saveTo & "\" & f.Name & ".xlsx", xlWorkbookDefault
        ActiveWorkbook.Close
    Next
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top