gpt4 book ai didi

excel - 使用VBA将xml文件转换为xlsx文件

转载 作者:行者123 更新时间:2023-12-04 21:59:05 24 4
gpt4 key购买 nike

如何转换 xml 文件到 xlsx ?
xml文件夹中存在的文件,我想保存 xlsx文件到另一个文件夹。

例子:

现有文件: C:\Users\John\Documents\xml\data.xml 转换为: C:\Users\John\Documents\xlsx\data.xlsx

最佳答案

我做的。

Public Sub ConvertXmlToXlsx()

Application.DisplayAlerts = False

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object

xmlFolder = "C:\Users\John\Documents\xml\"
convFolder = "C:\Users\John\Documents\xls\"


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 & "_conv.xlsx"

Set ConvertThis = Workbooks.Open(objFolder & "\" & objFile.Name)
ConvertThis.SaveAs Filename:=NewFileName, FileFormat:= _
xlOpenXMLWorkbook
ConvertThis.Close
End If
Next objFile

结束子

关于excel - 使用VBA将xml文件转换为xlsx文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38587755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com