Export From notepad to Excel

DaddyH

New Member
Joined
Jan 25, 2011
Messages
35
Hi guys, please could you help save me some time.

This is basically what i have:

250 folders (i folder per customer), each with 27 (months of info) notepad files, I need to write a macro which can open each notepad file for each customer then copy and paste the data into a different worksheet in a spreadsheet.

Does anyone have any ideas?

Cheers guys

Nick
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Maybe I'm missing something, but can't you just change the properties of the Notepad file to open with Excel? It will open in .csv and then you can Save As Excel Workbook. Then you can do a Text To Column to separate the data.

I apologize if I'm way off here.
 
Upvote 0
Hi there, thanks for the response, just tried that but it didn't work.

What i need is some script to open each notepad file and paste it into a seperate worksheet. i dont fancy 6750 file opens, 6750 select alls, 6750 copy's, 6750 goto worksheets, 6750 cell selects and 6750 pastes.

I think this will actually send me insane!

Cheers for your help

Nick
 
Upvote 0
What structure does the data exist in in the text files? In principal this is straightforward. Not sure you would want 6750 worksheets in the one workbook though! How much data is in each file? Sample of the data would help (obviously cleanse it of personal details/use dummy data)
 
Upvote 0
ok, the file names all look like this, with the exception of the customer name changing

Folder Name = Customer Name

within in folder i have a sub folder for the name of the region

eg West Midlands, East Midlands etc

Then i have the files named

CustomerName_RegionName_2009-03-01_2009-03-31_2011-05-31
CustomerName_RegionName_2009-04-01_2009-04-30_2011-05-31
CustomerName_RegionName_2009-05-01_2009-05-31_2011-05-31
etc (until present month)

The date looks like this:

30 0 0 0
0 0 0 0
0 2009 3 146037
0 2009 4 43808
0 2009 5 26323
0 2009 6 23672
0 2009 7 19246
0 2009 8 20915
0 2009 9 21906
0 2009 10 42298
0 2009 11 25716
0 2009 12 46824
0 2010 1 30241
0 2010 2 27209
0 2010 3 25620
0 2010 4 29398
0 2010 5 32697
0 2010 6 32195
0 2010 7 68743
0 2010 8 174692
0 2010 9 35377
0 2010 10 22554
0 2010 11 23955
0 2010 12 26408
0 2011 1 17691
0 2011 2 26526
0 2011 3 15648
0 2011 4 8902

Thanks for your help.

You ar eright i don't nessariliy need 6750 sheets, but i do need them seperating by customer by region. though.

Cheers

Nick
 
Upvote 0
Nick

I'm thinking that perhaps you don't need any of that data on separate sheets ie it can be tabularized as long as we include a customer name and region name field against the data (eg then you can pivot the data to summarise the results or use autofilter to return records specific to one customer/region?
 
Upvote 0
Hi Apologies for not getting back sooner, i've been away for a few days. What you suggest makes perfect sense. If you could help in any way it would be greatly appreciated.

Cheers

Nick
 
Upvote 0
Hi Nick

I am assuming you are using a version of Excel NEWER than xl2003!!!

Place this code in a standard module in a new file and change the TOP_FLDR constant value to be the path of the parent folder that contains all the customer folders & files. Then run the code. I assume there are no files contained within the folders that you do not wish to process (ie all the files contained within each region folder will be processed).

Code:
Sub Get_Customer_Data()

Const TOP_FLDR As String = "C:\Users\Richard\Documents\SpreadSheets\MrExcel\Parent" 'amend this to be the folder than contains all the others

Dim strTxt As String
Dim fso As Object, fl_top As Object, fl_Int As Object, fl_Bot As Object, f As Object

Dim ws As Worksheet
Dim lngNxtRw As Long
Dim i As Long, j As Long

Dim vArrParent, vArrChild

Set fso = CreateObject("Scripting.FileSystemObject")

Set fltop = fso.GetFolder(TOP_FLDR)

Set ws = Worksheets.Add

With ws
    With .Range("A1:G1")
        .Value = Array("Customer Name", "Region Name", "Link to source file", "First Column Value", "Year", "Month", "Value")
        .Font.Bold = True
    End With
    lngNxtRw = 2
    For Each fl_Int In fltop.SubFolders  'customer folder
        For Each fl_Bot In fl_Int.SubFolders  'region folders
            For Each f In fl_Bot.Files      'individual files
                strTxt = f.OpenAsTextStream(1).ReadAll  'get all the data
                strTxt = Replace(strTxt, vbCrLf, vbLf) 'ensure consistent delimiters to vbLf
                vArrParent = Split(strTxt, vbLf) 'store each line of data
                For i = 0 To UBound(vArrParent)
                    .Cells(lngNxtRw, 1) = fl_Int.Name
                    .Cells(lngNxtRw, 2) = fl_Bot.Name
                    .Hyperlinks.Add anchor:=.Cells(lngNxtRw, 3), Address:=f.Path
                    vArrChild = Split(vArrParent(i), " ")
                    .Cells(lngNxtRw, 4).Resize(, 4) = vArrChild
                    lngNxtRw = lngNxtRw + 1
                Next i
                Erase vArrChild
                Erase vArrParent
                strTxt = vbNullString
            Next f
        Next fl_Bot
    Next fl_Int
End With

End Sub

Code:
 
Upvote 0
Hi Richard, i have run the macro and now have a list of 65532 links to files. However there seems to be a problem with the information. I seem to have way to many lines eg:

Customer 1 folder has one country sub folder with 27 files in it. The macro has brought back 81 lines of data, why?

Custiomer 2 folder has one country sub folder with 27 files in it. The macro has brought back 216 lines of data.

Many Thanks for all your help! its really appeciated!

Regards

Nick
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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