Remember to not save the file after importing the data so that you can easily reset the file.
Figure 3-19 shows the new XML data appended to our existing worksheet.
Figure 3-19. New rows appended to Adventure Works employee information
There may be a case where you do not want to change the XMLSourceFile property but
still need to append data. Let??™s create a method in our class that allows us to point to the data
file directly.
First reset the file by closing without saving. Then reopen the file.
In the cXML class, add a method called AppendFromFile.We??™ll pass in the file name as an
argument and use the XmlMaps collection??™s Import method to append the data. The finished
method will look like this:
Public Function AppendFromFile(FileName As String)
'calling this function to append data will not modify the XMLSourceFile Property
ActiveWorkbook.XmlMaps(m_sMapName).Import FileName, False
End Function
Once again, this line of code is identical to the code in our earlier experiments, with the
exception of calling on the class??™s internal variable for the XML map name. We can quickly test
this method. Add a new subroutine to the standard module called AppendEmpDeptInfo. Add the
following code:
Public Sub AppendEmpDeptInfo()
'sample routine to get additional XML data w/o modifying XMLSourceFile Property
oEmpDept.AppendFromFile ??
"C:\Chapter 3\EmpDeptAdd.xml"
End Sub
CHAPTER 3 n USING XML IN EXCEL 2007 116
Run the GetEmpDept macro to get the initial data on the worksheet.
Pages:
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139