Microsoft Office Tutorials and References
In Depth Information
Although most of the properties and methods you’ll need to work with XML maps are con­
tained in the XmlMap object, the XmlMaps collection does contain the vital Add method,
which you use to assign a schema to a workbook. The Add method has this syntax:
Add(Schema, RootElementName)
The Schema argument is a string variable that contains the full path of the schema to add to
the workbook, and the RootElementName argument contains the name of the root element in
the schema. The following procedure adds the MySuppliers.xsd schema to the active
Sub ApplySchema()
Dim myMap As XmlMap
Dim xSchemaFile As String
xSchemaFile = “C:\MySuppliers.xsd"
Set myMap = ActiveWorkbook.XmlMaps.Add(xSchemaFile, “Root”)
End Sub
This procedure defines an object variable ( myMap ) to hold the reference to the XmlMap .
After you assign the schema file path to the xSchemaFile variable, you use the Set command
to assign the named schema file to the active workbook’s XmlMaps collection.
When you attach a map to a workbook, the map is assigned the name of the root element fol­
lowed by an underscore and the word Map . The map you just added, which has a root ele­
ment named Root, would be assigned the name Root_Map .
To delete the XmlMap you just added to your workbook, you would run the following proce­
Sub RemoveMap()
End Sub
Note If a map has been attached to a workbook and you attempt to assign the map to
the workbook again, Excel will add a number to the end of the map name. For example, add­
ing the Root_Map map to a workbook additional times would result in the map being named
Root_Map2 , Root_Map3 , and so on.
If you wanted to write the data currently within the cells assigned to the Root_Map schema to
a file named SuppliersBackup.xml, you could use the following procedure:
Search JabSto ::

Custom Search