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 126 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

Figure 3-17 shows the code in break mode when being run a second time.
Figure 3-18 shows the code falling into the Else statement and calling the RefreshXML
method instead when the XML map already exists.
CHAPTER 3 n USING XML IN EXCEL 2007 114
Figure 3-17. First time importing EmpDept.xml
Figure 3-18. Second time importing EmpDept.xml
Close the file without saving it, and then reopen it. Let??™s append some data contained in
another XML file that conforms to the same XML schema. In the same standard module, add
another method and name it GetAdditionalEmpDeptInfo.
Public Sub GetAdditionalEmpDeptInfo()
'appends data from files sent in from field offices.
If oEmpDept Is Nothing Then
Set oEmpDept = New cXML
End If
oEmpDept.XMLSourceFile = ??
"C:\Chapter 3\EmpDeptAdd.xml"
Set oEmpDept.DataRange = Sheets(1).Range("A1")
oEmpDept.GetXMLData False
End Sub
Save the file after adding this code.
CHAPTER 3 n USING XML IN EXCEL 2007 115
This function might be used to append data from files you receive on a regular basis.
Run the GetEmpDept macro once again. Open the Macro dialog and run the
GetAdditionalEmpDeptInfo subroutine to append the new data.
Let??™s take a look at what this code is doing. First we check to see that we have created an
oEmpDept object, and if not, create one. Then we set the XMLSourceFile property to the location
of the file containing the additional XML data (otherwise, we??™ll just append the same data to
our list). Once that??™s done, we call the GetXMLData method again, but this time we pass in the
Overwrite flag with a value of False to tell the method to append the data.


Pages:
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138