Some data was truncated"
End Select
End Function
Let??™s create some client code to test our cXML class out as we build it.
CHAPTER 3 n USING XML IN EXCEL 2007 113
Add a standard module to the workbook, and declare a module-level variable:
Dim oEmpDept As cXML
Add a new procedure and name it GetEmpDept. Add the following code:
nNote Be sure to change the file path to where you have the XML file stored.
Public Sub GetEmpDept()
Set oEmpDept = New cXML
oEmpDept.XMLSourceFile = ??
"C:\Chapter 3\EmpDept.xml"
Set oEmpDept.DataRange = Sheets(1).Range("A1")
oEmpDept.GetXMLData
End Sub
Before running the client code, save your work. We are going to import some test data,
and then we??™ll close the workbook without saving to remove the data and XML maps between
each test. This is an easy way to reset the project without deleting worksheets and XML maps
between tests.
Our data file contains a listing of Adventure Works employees and their department and
job information. Since the object is just being instantiated here and its MapName property is
empty, the code will fall into the first branch of the If statement and call the GetNewXMLData
method.
Run the GetEmpDept procedure. Figure 3-16 shows the last few rows of the imported XML
data.
Figure 3-16. Last few rows of AdventureWorks employee XML file
Run the GetEmpDept procedure once again. This time, the data is just refreshed. If you
need to see the proof, put a breakpoint in the GetEmpDept procedure before you run it the
second time.
Pages:
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137