Convert each row of a spreadsheet into a .txt or .xml file?

nickf829

New Member
Joined
Nov 18, 2011
Messages
15
I have a spreadsheet with thousands of lines of a very small code. Each row contains a complete code that needs to either be converted/pasted into a new .txt or .xml document. The name of the new doc is irrelevant, but if it's possible to control the naming convention that would help(i.e. another cell with a suggested name). This will result in thousands of small .txt/.xml files. Until now, just copying and pasting each line into a .txt file was necessary but there has to be a way to simplify this. I would love to know if it's possible to extract each row and create or add it it to a new .txt or .xml file?

Thanks!
 
Last edited by a moderator:
For the first one (highlighted in red)... what should it look like in the text file you want created for it? Like this maybe...

Name1
Address1
Phone Number1
etc.

Output will be fine even as following:

Name 1 Address 1 Phone Number 1
Name 2 Address 2 Phone Number 2

The only issue with above code is that it is not converting all rows into HTML.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
The reason that it's skipping rows is because the current row is being deleted after it's copied to the new workbook, but then the For each/Next control kicks in and increments the counter. If you just delete the line of code that's deleting the active row, you should not lose any of your data.
Hope that helps,
 
Upvote 0
Hi Cindy and Experts,

I tried your code but it seems that it is not taking the complete text in the column. Is there any limit on number of words which can be extracted from a cell?
Below is the code which I am using and facing issue.
Sub Rishabh()
'
Dim i As Long
Dim LastDataRow As Long
Dim MyFile As String
Dim fnum


LastDataRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastDataRow
'The next line uses the contents of column B on the same row to name it
MyFile = "C:\Users\Rishab760605\Desktop\Excel\" & ActiveSheet.Range("B" & i).Value & ".txt"
'Use the following line instead to just create a series of numbered files
'MyFileName = "C:\Users\Rishab760605\Desktop\Excel\" & i & ".txt"
fnum = FreeFile()
Open MyFile For Output As fnum
Print #fnum, Format(Range("C" & i))
Close fnum
Next
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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