创build用于将XML导出到某个文件夹的Excelmacros

我需要创build一个macros(我从来没有做过),如果你们能指导我走正确的道路,那将是非常感激的。

目前我在做什么:我已经创build了一个映射XML,我已经导入到Excel中。 一旦导入到Excel中,用户将继续粘贴一些数据并导出,以接收XML数据文件,然后用户可以将其放到FTP中,然后作业将其导入数据库。

这是问题:导出有以下节点,我不想要:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

相反,我想用下面的代替它:

 <?xml version="1.0" ?> <Root xmlns="http://tempuri.org/CourseImport.xsd"> 

我该如何自动化? Excel中是否有某种设置可以使其发生?

基本上,我想导出有我的根,而不是默认的根,我想自动能够将文件放到指定的path:例如:\开发\学校\课程导入

谢谢!

我的同事实际上帮助了我。 我以为我应该分享我所做的

 Sub ExportXML() ' ' Export XML Macro exports the data that is in Excel to XML. ' Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") ' newFileName = Application.GetSaveAsFilename("out.xml", "XML Files (*.xml), *.xmls") If newFileName = False Then Exit Sub End If If objFSO.FileExists(newFileName) Then objFSO.DeleteFile (newFileName) End If ActiveWorkbook.XmlMaps("Root_Map").Export URL:=newFileName Set objFile = objFSO.OpenTextFile(newFileName, ForReading) Dim count count = 0 Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If count = 0 Then strNewContents = strNewContents & "<?xml version=""1.0"" ?>" & vbCrLf ElseIf count = 1 Then strNewContents = strNewContents & "<Root xmlns=""http://tempuri.org/import.xsd"">" & vbCrLf Else strNewContents = strNewContents & strLine & vbCrLf End If count = count + 1 Loop objFile.Close Set objFile = objFSO.OpenTextFile(newFileName, ForWriting) objFile.Write strNewContents objFile.Close End Sub