Hi Chris,
Your asking a lot there....this will take a few posts...
What your doing at the moment by calling OpenXML, I believe, is creating a workbook containing a sheet named after the element which 'name' and 'subjectID' is in. The sheet contains your example data there with row 1 containing the name and subjectID headings. Is that correct?
your xml will look like this
<root>
<entry><name>...</name><subjectID>...</subjectID></entry>
and this becomes a sheet named entry, with row 1 containing headings name and subjectID
If this does happen then you've read the XML in OK and you no longer need to worry about thinking in terms of XML but in terms of an worksheet, which is similar to an array. The sheet generated is like an array, are you familiar with them?
What you would do is loop down the rows of the sheet accessing each column of the row applying steps 3, 4, and 5 to each row. This looping is fairly common, it's not the best performance wise but you know. Your column references will be fairly static column 1 = name and column 2 = subjectID, but your CurrentRow increments a line at a time so use a variable for this. Your loop needs to have an end point, a last row where the data stops.
Dim nEndRowIndex As Double nEndRowIndex = ActiveWorkbook.Worksheets(SheetName).Range("A2").End(xlDown).Row
The code above should give you the last row containing data.
While the code that loops will be similar to this...
Dim nCurrentRow As Integer 'for the start row to the end row For nCurrentRow = 2 To nEndRowIndex 'name and subjectID msgbox(ActiveWorkbook.Worksheets(SheetName).Cells(nCurrentRow, 1))
msgbox(ActiveWorkbook.Worksheets(SheetName).Cells(nCurrentRow, 2))
Next
If you can get the loop going then post again about opening the file and applying a formula and I'll help you out.
www.dsmyth.net/blog |