xml - 如何在 VBA 中重命名 .xml 文件
问题描述
我需要在 VBA 中编辑一个 .xml 文档,并且我喜欢保留原始 xml (ppp.xml) 和单独的新编辑文件(我想调用 pppnew.xml),基本上不更新原始文件。由于我是基本用户,我从以下代码开始:
Sub editxml()
Dim Obj As MSXML2.DOMDocument
Dim xmlpath As String
Set Obj = New DOMDocument
Obj.async = False
Obj.validateOnParse = False
xmlpath = "C:\Users\xxx\Desktop\ppp.xml"
Obj.SetProperty "SelectionNamespaces", "xmlns:ns0='http://update.DocumentTypes.Schema.ppp.Xml'"
If Obj.Load(xmlpath) = True Then
MsgBox "File XML uploaded"
Else
MsgBox "File XML not uploaded"
Exit Sub
End If
'My code follows here
Obj.Save xmlpath
End sub
我试图编辑以下代码行
SelectionNamespaces", "xmlns:ns0='http://update.DocumentTypes.Schema.ppp.Xml'
通过将其更改为
SelectionNamespaces", "xmlns:ns0='http://pppnew.Xml'
但它不起作用:代码更新了原始文件,我想保持未编辑。
解决方案
您实际上是将修改保存在 SAME 文件中
改变
Obj.Save xmlpath
到
new_xmlpath = "C:\Users\xxx\Desktop\new.xml"
Obj.Save new_xmlpath
推荐阅读
- nestjs - Prisma 客户端类型系统创建与服务方法的强耦合
- google-sheets - 如何使用 Google Doc 获取实时报价?
- logging - 我们如何从日志中获取哨兵实体,我们对实体的 KQL 查询是什么,哨兵 ID 信息
- sql - BigQuery 中的多个联合自联接
- python - ValueError:对已关闭文件的 I/O 操作,flush()
- sql - 我有一个 Sql 表中日期之间的差异总和。如何计算以天、小时、分钟为单位的平均值?
- go - go-git 从轻量级标签中获取树
- html - 应用 z-index 时,非嵌套 div 是否算作兄弟?
- mysql - 无法安装 MySQL
- python - PyInstaller + Wine + NLTK = WinError 127 "RtlIpv6AddressToStringA"。有任何想法吗?