我的文件夹中有很多xml格式的文件。 我想从中提取特定数据。 我编写了一个宏来获取所需的内容,但是从xml中我无法获取特定数据。
我尝试将文件另存为csv和宏作品。
但是我像文件一样保存到csv->另存为.. 如果我尝试将文件转换为csv,它将转换为xlm文件中的所有属性。
我如何一次转换所有xml文件,以仅获取包含我需要的数据而没有属性的csv文件??
Public Sub ConvertXmlToXlsx()
Application.DisplayAlerts = False
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
xmlFolder = "C:\Users\valesk1\Desktop\Calibration_\test\LOG\"
convFolder = "C:\Users\valesk1\Desktop\Calibration_\test\LOG\csv\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(xmlFolder)
For Each objFile In objFolder.Files
If UCase(Right(objFile.Name, Len(XML))) = UCase(XML) Then
NewFileName = convFolder & objFile.Name & ".csv"
Workbooks.OpenXML (objFolder & "\" & objFile.Name), LoadOption:=xlXmlLoadImportToList
ActiveWorkbook.SaveAs Filename:=NewFileName
ActiveWorkbook.Close
End If
Next objFile
End Sub
我想将xml转换为csv,不带任何属性,仅返回结果
答案 0 :(得分:0)
Public Sub ConvertXmlToXlsx()
Application.DisplayAlerts = False
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
xmlFolder = "C:\Users\valesk1\Desktop\Calibration_\test\LOG\"
convFolder = "C:\Users\valesk1\Desktop\Calibration_\test\LOG\csv\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(xmlFolder)
For Each objFile In objFolder.Files
If UCase(Right(objFile.Name, Len(XML))) = UCase(XML) Then
NewFileName = convFolder & objFile.Name & ".csv"
Workbooks.OpenXML (objFolder & "\" & objFile.Name), LoadOption:=xlXmlLoadImportToList
ActiveWorkbook.SaveAs Filename:=NewFileName, FileFormat:=xlCSVUTF8
ActiveWorkbook.Close
End If
Next objFile
End Sub