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

Jim DeMarco

"Pro Excel 2007 VBA"

Then run the
AppendEmpDeptInfo procedure from the Macro dialog box. The result is identical, but
the XMLSourceFile property was not modified.
In case the contents of the file you??™re reading will be updated from time to time by external
sources, the XmlMaps collection has the ability to refresh the data source.
Add a new method to the cXML class called RefreshXML. Here is the code for the RefreshXML
method:
Public Function RefreshXML()
ActiveWorkbook.XmlMaps(m_sMapName).DataBinding.Refresh
End Function
Now that we have our XML data in a worksheet, we can modify it or add records. We need
to add one last bit of functionality to our class: the ability to save the data back to XML. Reset
your project by closing without saving and reopening it.
Add a new method to the cXML class called SaveToFile. The finished SaveToFile method
will look like this:
Public Function SaveToFile(Optional SaveAsFileName As String = "FileNotSet")
'if no SaveAsFileName is provided the current XMLSourceFile will be overwritten
Dim ExportMap As XmlMap
If SaveAsFileName = "FileNotSet" Then
SaveAsFileName = m_sXMLSourceFile
End If
Set ExportMap = ActiveWorkbook.XmlMaps(m_sMapName)
If ExportMap.IsExportable Then
ActiveWorkbook.SaveAsXMLData SaveAsFileName, ExportMap
Else
MsgBox ExportMap.Name & " cannot be used to export XML"
End If
End Function
We??™ve included an optional argument for the file name of the saved document and
passed in a default nonsense value. If we want to save the data back to the file from which it
came, we simply call the method with no argument.


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