LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBS script to add xml data to excel


I am really new at this vbs stuff and using XML in excel and have come
up with a partial solution looking at the net and have come this far.
But still not there.

I have been successful in creating a script to map .XSD schema to Excel
and then import the data from a file into excel through a script. But
my goal was to be able to change the data and export it back to XML.
The script I was able to make created Column Lists in my excel doc and
that can not be exported. How do I map my .XSD into excel without it
being in Column List fomat.

The below script is dynamic and being created outside of any
conventional editor and will change based on what fields I want to
bring into excel. But the goal is the same, export it from my
database to excel using xml, then change it in excel and create an xml
document using the save as option of excel and take tha final xml doc
back to my database. All this is started outside of a MS environment.


Dim xapp
Dim workbook
Dim actColumn
Dim worksheet
Dim strXpath
Dim objMap
Dim strXMLPath
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
AbsolutePath = fso.GetAbsolutePathName(path)
strXMLPath = AbsolutePath & "\BOBBY.xml"
actColumn = 0
' Create a new Excel workbook
set xapp = WScript.CreateObject("Excel.Application")
xapp.Visible = True
set workbook = xapp.Workbooks.Add
set worksheet = workbook.Worksheets("sheet1")
' Add XML Data map
set objMap = workbook.XmlMaps.Add(AbsolutePath &
"\BOBBY.xsd","PowerShift")
'Map elements into spread sheet
strXPath = "/PowerShift/C1A/Customer_number"
Set xp = worksheet.Range("A1:A2").Offset(1,actColumn).XPath
xp.SetValue workbook.XmlMaps(1), strXPath
actColumn = actColumn + 1

'Map elements into spread sheet
strXPath = "/PowerShift/C1A/Customer_type"
Set xp = worksheet.Range("A1:A2").Offset(1,actColumn).XPath
xp.SetValue workbook.XmlMaps(1), strXPath
actColumn = actColumn + 1
'Map elements into spread sheet
strXPath = "/PowerShift/C1A/Xref"
Set xp = worksheet.Range("A1:A2").Offset(1,actColumn).XPath
xp.SetValue workbook.XmlMaps(1), strXPath
actColumn = actColumn + 1
'Map elements into spread sheet
strXPath = "/PowerShift/C1A/Freight_terms"
Set xp = worksheet.Range("A1:A2").Offset(1,actColumn).XPath
xp.SetValue workbook.XmlMaps(1), strXPath
actColumn = actColumn + 1
'Import XML file into mapped elements
objMap.Import strXMLPath
'Save workbook as:'
workbook.SaveAs(AbsolutePath & "\BOBBY.xls")


--
roblo
------------------------------------------------------------------------
roblo's Profile: http://www.excelforum.com/member.php...o&userid=22469
View this thread: http://www.excelforum.com/showthread...hreadid=398418

 
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
Can't Download Data in Thai Script Victor Viguilla Excel Discussion (Misc queries) 0 June 1st 06 03:51 AM
Importing Data - Macro or Script Norgbort Machine Excel Worksheet Functions 0 May 3rd 06 09:53 PM
getting data from excel worksheet in to a script nuti Excel Discussion (Misc queries) 0 January 12th 06 08:48 AM
Data match using VB script Lillian[_5_] Excel Programming 2 August 9th 04 10:16 PM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM


All times are GMT +1. The time now is 08:53 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"