#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default XML File


Using Excel's XML maps can be tricky and you need the maps to use the
Save As XML option. I find it simpler to just write the XML data
directly. The following is some code I wrote a while ago. To use it,
select the data that you want to export as XML and then run the code.
It will prompt you for an output file name. The code assumes that the
first row of the selection is column headers to be used as element
names in the XML. Change the lines marked with <<< to the correct
values. RootName is the name of the root elemnt of the XML document.
RowName is the element name for each row of data. The result is a very
simple XML file, with attributes, namespace declarations, or schema
references. You could easily modifty the code to add these features.

Sub QDXML()

Dim FName As Variant
Dim FNum As Integer
Dim Root As Range
Dim RootName As String
Dim RowName As String
Dim RNdx As Long
Dim CNdx As Long

FName = Application.GetSaveAsFilename(filefilter:="XML Files,*.xml")
If FName = False Then
Exit Sub
End If

Set Root = Selection.Cells(1, 1)
RootName = "DocElement" '<<< name of root XML element
RowName = "Item" '<<< row element name

FNum = FreeFile
Open FName For Output Access Write As #FNum
rint #FNum, "<?xml version=""1.0"" encoding=""UTF-8""?"
Print #FNum, "<" & RootName & ""
For RNdx = 1 To Selection.Rows.Count
Print #FNum, Space(4) & "<" & RowName & ""
For CNdx = 1 To Selection.Columns.Count
Print #FNum, Space(8) & _
"<" & Selection.Cells(1, CNdx) & "" & _
Selection.Cells(RNdx, CNdx) & "</" & _
Selection.Cells(1, CNdx) & ""
Next CNdx
Print #FNum, Space(4) & "</" & RowName & ""
Next RNdx
Print #FNum, "</" & RootName & ""
Close #FNum
End Sub



Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com




On Fri, 5 Mar 2010 18:55:31 -0800, Thanks
wrote:

Hello
What is the process for creating an XML file from a spreadsheet?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
open text file, get file from directory, update file Diana Excel Programming 2 February 3rd 10 05:28 AM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
I saved file A over file B. Can I get file B back? Lynn Excel Discussion (Misc queries) 2 May 12th 06 11:24 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
i received a file that reads powerpoint document file file exten. CCAROLACEREC Excel Discussion (Misc queries) 1 December 4th 04 05:02 PM


All times are GMT +1. The time now is 06:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"