首页 > 解决方案 > 在 VBA 中使用单元格中的文件路径

问题描述

我正在使用 VBA 中的 .xml 文件,并且我想让文件路径动态化,因为宏必须在许多不同的 .xml 文件上运行,所以每次我使用时都不需要编辑代码它。我尝试了以下方法,这使得文件的正确路径可以在即时窗口中正确打印,但它不会打开它。我正在引用 Microsoft XML,v3.0。

我如何也可以动态编辑代码的 SelectionNameSpaces 行?

Sub openxml()
Dim Obj as DOMDocument
Dim xmlpath as String

Set Obj=New DOMDocument
Obj.async=False
Obj.validateOnParse=False

xmlpath=ThisWorkbook.Worksheets(1).Range("B4").Value
Debug.Print xmlpath

'''Obj.SetProperty "SelectionNameSpaces", "xmlns:ns0='http://update.DocumentTypesSchema.myfile.Xml' " '''

If Obj.Load(xmlpath)=True Then
   Msgbox ".xml uploaded"
Else
   Msgbox ".xml not uploaded"
   Exit Sub
End If

End Sub

标签: xmlvbapath

解决方案


推荐阅读