We??™ve also added an overwrite flag and
a read-only property to retrieve the name of the XML map for this object.
The module-level declarations section should now look like this:
Dim m_sXMLSourceFile As String
Dim m_blnOverwrite As Boolean
Dim m_oRange As Excel.Range
Dim m_sMapName As String
Now let??™s start getting some work done. We are going to build, import, append, refresh,
and save functions for our XML data. The first step is to get data from the XML file into the
worksheet. We have a few scenarios in which to put data on our worksheet:
??? Bringing in data from an XML file
??? Overwriting existing XML data with a file that shares the same schema
??? Appending XML data to our existing XML data
We??™ll start out by building a function that gives a developer who might be using this class
in a project the ability to bring in new data (thereby creating an XML map) and a function to
add additional data to previously imported XML data (or overwrite it if desired). These will be
declared as private functions within the class. We will create a wrapper method to let our code
make the decision as to which process we are calling. We??™ll also add a method to provide a
direct call to an append function.
CHAPTER 3 n USING XML IN EXCEL 2007 110
In the cXML class module, add a private method named GetNewXMLData. The code for this
method will look very familiar:
Private Function GetNewXMLData()
ActiveWorkbook.XmlImport m_sXMLSourceFile, Nothing, m_blnOverwrite, m_oRange
m_sMapName = ActiveWorkbook.
Pages:
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132