我有一个VBA代码来读取XML,如下所示
strTargetFile = "C:\Users\XXXXXX\Desktop\XXXXXX\XXXX\XML\Details.xml"
Set wb = Workbooks.OpenXML(Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList)
有没有办法删除这个硬编码?
答案 0 :(得分:0)
如果您的XML文件夹与工作簿文件夹位于同一文件夹中,请尝试以下操作:
sParentFolder = Left(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\") - 1)
strTargetFile = sParentFolder & "\XML\Details.xml"
Set wb = Workbooks.OpenXML(Filename:=strTargetFile,LoadOption:=xlXmlLoadImportToList)