SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 122 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


Now let??™s add that wrapper method and let our class decide how to handle the data
retrieval. Add a public function to the cXML class and name it GetXMLData. Add the following
code:
Public Function GetXMLData(Optional DoOverwrite As Boolean = True)
If (m_sMapName = "") Or (Not Me.HasMaps) Then
GetNewXMLData
Else
'must set XMLSourceFile Property before appending if necessary
GetXMLForExistingMap DoOverwrite
End If
End Function
The GetXMLData method has one optional argument, which is used to set an overwrite flag
for the incoming data. This argument has a default value of True, remaining consistent with
Excel??™s built-in object interfaces.
CHAPTER 3 n USING XML IN EXCEL 2007 111
The code begins with branching logic to determine whether our object already contains
a reference to an XML map or whether the workbook does not contain any XML maps.
Once that??™s determined, the code will either bring in new data and create an XML map
via the private GetNewXMLData function or it will call GetXMLForExistingMap, where, depending
on how the overwrite flag is set, it will either append or overwrite the data in the existing
mapping. The second branch also contains a comment noting that the XMLSourceFile property
should be set before calling this function to perform an append.
Before we create client code to test this, remember that the original GetXMLData function
that we wrote in our standard module in a previous example generated an error if it was run
two times in a row (against a data table that was already mapped).


Pages:
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134