Create individual files from a row

G

GrahamN

I have an excel file with several thousand entries, which contain data
in several columns. I would like to be able to create an individual
xml or html file for each row, but with predifined formatting around
so

Mr A bloggs, A street, A town, AA1 1AA

Could become Abloggs.html

<head></head>
<name>Mr A bloggs</name>
<street>A street</street>
Any other info here as well
</html>

etc. Is this possible and any suggestions how?

thanks,
Graham.
 
G

Guest

Graham,

How good is your HTML coding?

You could write a macro to do exactly what you want.

HTH
 
G

GrahamN

I guessed a Macro may be the way, but this is an area I'm not too clued
up on :confused: Anyone know any good resources?
 
D

Dave Peterson

I have no idea where the data is kept (different columns I hope???).

But this may give you some ideas:

Option Explicit
Sub testme()

Dim myFileName As String
Dim FileNum As Long

Dim myFolder As String

Dim FirstRow As Long
Dim LastRow As Long
Dim iRow As Long

'make sure it exists!
myFolder = "C:\temp"
If Right(myFolder, 1) <> "\" Then
myFolder = myFolder & "\"
End If

With Worksheets("sheet1")
FileNum = FreeFile
FirstRow = 2 'headers in row 1??
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow

Close FileNum
myFileName = myFolder & "out" _
& Format(iRow - FirstRow + 1, "0000") & ".txt"

Open myFileName For Output As FileNum

Print #FileNum, "<head></head>"
Print #FileNum, "<name>" & .Cells(iRow, "A").Text & "</name>"
Print #FileNum, "<street>" & .Cells(iRow, "b").Text & "</street>"
Print #FileNum, "Any other info here as well"
Print #FileNum, "</html>"

Close FileNum

Next iRow

End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top