loop through (should be easy)

B

buffyslay

:eek:
hi there

need to loop through and get the data into an xml file (dont ask why)

currently have this code:
but all it does is loop through randomly.... please help - just go
back from maternity leave and left my brain at home!!

Sample:
A1 A1 A1 A1 A1 A1
A1 A1 A1 A1 A1 A1
B1 B1 B1 B1 B1 B1
A1 A1 A1 A1 A1 A1
B1 B1 B1 B1 B1 B1
C1 C1 C1 C1 C1 C1
A1 A1 A1 A1 A1 A1



***********************************************

Public Sub OutputQuoted()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim i, j, k As Integer
Dim nFileNum As Long
Dim sOut As String

Dim groupTitle, mapping, Description, budgetCode, budgetCodePT
budgetCodeLU As String
Dim groupTitleEND, mappingEND, DescriptionEND, budgetCodeEND
budgetCodePTEND, budgetCodeLUEND As String
groupTitle = "<groupTitle>"
mapping = "<mapping>"
Description = "<description>"
budgetCode = "<budgetCode>"
budgetCodePT = "<budgetCodePT>"
budgetCodeLU = "<budgetCodeLU>"

groupTitleEND = "</groupTitle>"
mappingEND = "</mapping>"
DescriptionEND = "</description>"
budgetCodeEND = "</budgetCode>"
budgetCodePTEND = "</budgetCodePT>"
budgetCodeLUEND = "</budgetCodeLU>"

nFileNum = FreeFile
Open "C:\Documents and Settings\pxthom\Desktop\xmlTest\test1.xml
For Output As #nFileNum

Print #nFileNum, "<?xml version= " & Chr(34) & "1.0" & Chr(34) &
encoding=" & Chr(34) & "ISO-8859-1" & Chr(34) & " ?>"
Print #nFileNum, "<?xml-stylesheet type=" & Chr(34) & "Text/xsl"
Chr(34) & " href=" & Chr(34) & "simple.xsl " & Chr(34) & " ?>"
Print #nFileNum, "<topLevel>"

For Each myRecord In ActiveCell.CurrentRegion.Cells
With myRecord
i = 1

For Each myField In Range(.Cells(1), Cells(.Row, i).End(xlToLeft))
If myField = "" Then
myField = "-"
End If
i = i + 1
sOut = sOut & "<note>"
sOut = sOut & groupTitle & myField.Text & groupTitleEND
i = i + 1
sOut = sOut & mapping & myField.Text & mappingEND
i = i + 1
sOut = sOut & Description & myField.Text & DescriptionEND
i = i + 1
sOut = sOut & budgetCode & myField.Text & budgetCodeEND
i = i + 1
sOut = sOut & budgetCodePT & myField.Text & budgetCodePTEND
i = i + 1
sOut = sOut & budgetCodeLU & myField.Text & budgetCodeLUEND
sOut = sOut & "</note>"

Next myField
Print #nFileNum, sOut
sOut = Empty
End With
Next myRecord

Print #nFileNum, "</topLevel>"
Close #nFileNum
End Su
 

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

Similar Threads

looping through current region 2
Looping 1
Excel to txt 2
Automated " delimiter adder? 1
Double quote delimiter script 0
Comma Delimited Export 2
Changing a macro to save as Unicode text 2
Macro help! 4

Top