While looking at other posts I ran across enough info to recall how to
do this.
Thanks anyway....

Public Sub WriteXML()
' quick and dirty macro to write generated XML data to seperate files.
' Flename is based on worksheet path, run number and row number
    RunCol = Range("run").Column
    XmlCol = Range("Xml").Column
    FilePath = ActiveWorkbook.Path
    Set fs = CreateObject("Scripting.FileSystemObject")
    LastRow = Cells.Find("*", ActiveCell.SpecialCells(xlLastCell), , ,
xlByRows, xlPrevious).Row
    For Row = 2 To LastRow
        XML = Cells(Row, XmlCol).Value
        If XML Like "<?xml*" Then
            Filename = FilePath + "\Run_" + _
                Format(Cells(Row, RunCol).Value) + "_" + _
                Format(Row) + ".xml"
            Set a = fs.CreateTextFile(Filename, True)
            a.WriteLine XML
            a.Close
        End If
    Next
    Cells(2, RunCol).Value = Cells(2, RunCol).Value + 1
End Sub


RickB wrote:
> Once, long ago I used to write stuff like this but it's been too many
> years and I don't remember where to start.
>
> I'm using Excel to generate test data.
>
> The sheet has all the data I need calculated.
> Now I need a macro to loop thru a named range of cells and write the
> value of each cell to a new file who's name I can easily calculate
> (like file-a1.txt, file-a2.txt...).
>
> Help appreciated.

--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to [email protected]
If you find any spam message in the group, please send an email to:
Ayush Jain  @ [email protected] or
Ashish Jain @ [email protected]
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to