Parameters:
VBA . , . , . , , , , ( ).
, Excel 2007 . : Excel 2003 () Excel 2010 ( ).
Excel Xml- , .
:
- , (, , , ).
- XML. , . , XML, . . , ( ) XML. , , , , . XML:
( SO )
<x2:Field x2:ID="Add-E-head">
<x2:Range>RC[4]</x2:Range>
<x2:XPath>Add-E-head</x2:XPath>
<x2:XSDType>string</x2:XSDType>
<ss:Cell>
</ss:Cell>
<x2:Aggregate>None</x2:Aggregate>
</x2:Field>
: [// ] ( , ):
- .
- XML. . XML.
- . XML-.
- /, : , , XML.
- , , , . , , XML, .
- , XML.
- ( , ).
- , ( ).
- 4 8 , . , , .
- XML.
, XML- . , 3 , (.. 1a) XML- . XML 10, , .
. 3 4 XML. 1-1 XMl.
, , . , , SO-XML mapping.xml, , ( )
, ( ):
, , , - XML, . () , . , , , / . , , , .
INDIRECT() , . . , , . , , , , , . , , , .
( ) , . , , . , , ( , , ).
, , , . , .
. , C:\. , XML- , C:\ - , , Excel.
VBA KMKfan 16 2009 :
XML- - / (archive) ( XML Mapping Feature, ).
:
. XML , xsd xml- ( : "MyMap" MyMap.xsd. , XML . .
Dim r, c As Integer
Dim wb1, wb2 As Workbook
Dim StrMap, StrWS, StrRng, StrXPath As String
Dim nStrWS, nStrRng, nStrXPath As String
Dim nStrMap As XmlMap
Sub Update_XML()
Call Get_XPath
Call Add_NewMap
Call Assign_Elements
End Sub
Sub Get_XPath()
'Gets Available XML Mappings (XPath) for current workbook and sends the text information to a temp file.
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Add
wb1.Activate
For Each Sheet In wb1.Sheets
Sheet.Select
Range("A1").Select
Selection.UnMerge
For c = 1 To ActiveSheet.UsedRange.Columns.Count
For r = 1 To ActiveSheet.UsedRange.Rows.Count
If ActiveCell.Offset(r - 1, c - 1).XPath <> "" Then Call Send_XPath
wb1.Activate
Next r
Next c
Selection.Merge
Next Sheet
End Sub
Sub Send_XPath()
'Sends text information to a temporary workbook for use later.
StrWS = ActiveSheet.Name
StrRng = ActiveCell.Offset(r - 1, c - 1).Address
StrXPath = ActiveCell.Offset(r - 1, c - 1).XPath
StrMap = ActiveCell.Offset(r - 1, c - 1).XPath.Map.Name
With wb2
.Activate
ActiveCell = StrMap
ActiveCell.Offset(0, 1) = StrWS
ActiveCell.Offset(0, 2) = StrRng
ActiveCell.Offset(0, 3) = StrXPath
ActiveCell.Offset(1, 0).Select
End With
End Sub
Sub Add_NewMap()
'Delete the current XML map and add a new XML Map that has the same schema structure.
'XML Map and XSD schema must be named identically. Only the .xsd extension should be different.
Dim MyPath, MyMap As String
MyPath = 'Path of .xsd file goes here
For Each XmlMap In wb1.XmlMaps
MyMap = XmlMap.Name
wb1.XmlMaps(XmlMap.Name).Delete
wb1.XmlMaps.Add(MyPath & "\" & MyMap & ".xsd").Name = MyMap
Next XmlMap
End Sub
Sub Assign_Elements()
'Assign XPath of new XML Map to ranges based on the information in the temp workbook. Close 2nd workbook w/o saving.
With wb2
.Activate
Application.Goto Range("$A$1")
End With
Do Until ActiveCell = ""
Set nStrMap = wb1.XmlMaps(ActiveCell.Text)
nStrWS = ActiveCell.Offset(0, 1)
nStrRng = ActiveCell.Offset(0, 2)
nStrXPath = ActiveCell.Offset(0, 3)
With wb1
.Activate
Sheets(nStrWS).Select
Range(nStrRng).XPath.SetValue nStrMap, nStrXPath
End With
wb2.Activate
ActiveCell.Offset(1, 0).Select
Loop
wb2.Close False
End Sub