Now we??™ll modify the private method, GetNewXMLData, to use CurrentMapName and to give
us a return value on our import. And while we??™re at it, we??™ll add a result output to
GetXMLForExistingMap, and finally, the GetXMLData method will respond to those results with
a message to the user. The finished code for all three methods looks like this:
CHAPTER 3 n USING XML IN EXCEL 2007 112
Private Function GetNewXMLData() As XlXmlImportResult
Dim sCurrMap As String
Dim result As XlXmlImportResult
'check to see if data range is already bound to a map
sCurrMap = CurrentMapName
If sCurrMap = "" Then
result = ActiveWorkbook.XmlImport(m_sXMLSourceFile, Nothing, ??
m_blnOverwrite, m_oRange)
m_sMapName = ActiveWorkbook.XmlMaps(ActiveWorkbook.XmlMaps.Count).Name
Else
m_sMapName = sCurrMap
ActiveWorkbook.XmlMaps(m_sMapName).DataBinding.Refresh
result = xlXmlImportSuccess
End If
GetNewXMLData = result
End Function
Private Function GetXMLForExistingMap(DoOverwrite As Boolean) As XlXmlImportResult
'calling this function to append data requires ??
setting the XMLSourceFile Property
Dim result As XlXmlImportResult
result = ActiveWorkbook.XmlMaps(m_sMapName).Import(m_sXMLSourceFile, DoOverwrite)
GetXMLForExistingMap = result
End Function
Public Function GetXMLData(Optional DoOverwrite As Boolean = True)
Dim result As XlXmlImportResult
If (m_sMapName = "") Or (Not Me.HasMaps) Then
result = GetNewXMLData
Else
'must set XMLSourceFile Property before appending if necessary
result = GetXMLForExistingMap(DoOverwrite)
End If
Select Case result
Case xlXmlImportSuccess
MsgBox "XML data import complete"
Case xlXmlImportValidationFailed
MsgBox "Invalid document could not be processed"
Case xlXmlImportElementsTruncated
MsgBox "Data too large.
Pages:
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136