查找并replace – XML到Excel

正如标题所示,我有一个包含许多关键字(即数字1-30)的xml文件,我想用Excel表格(即31-60)中的其他关键字replace。 31-60在同一行中。 我试图打开xml文件,在xml中find1-30的位置,依次replace它们,使得1被replace为31,2被replace为32等。然后,我想要将新文件保存到新的文件位置给它一个新的名字。 如果可能的话,我想循环处理多行数据,最终我会得到许多不同数据的xml文件。 这是迄今为止的代码。 我也得到一个path/文件访问错误“打开sFileName输出为iFileNum”。 我会很感激任何帮助。 感谢您抽时间阅读。

Sub replace_strings()

Option Explicit Dim string_name(1 To 30) As Variant Dim file_name As String Dim sBuf As String Dim sTemp As String Dim iFileNum As Integer Dim sFileName As String Dim count As Integer count = 1 Windows("Excel File Name.xlsm").Activate Range("B4").Activate file_name = ActiveCell Do While ActiveCell <> "" ActiveCell.Offset(0, 1).Activate string_name(count) = ActiveCell count = count + 1 Loop sFileName = "C:\XML file location.xml" iFileNum = FreeFile Open sFileName For Input As iFileNum Do Until EOF(iFileNum) Line Input #iFileNum, sBuf sTemp = sTemp & sBuf & vbCrLf Loop Close iFileNum sTemp = Replace(sTemp, "bcsx", string_name(1)) iFileNum = FreeFile Open sFileName For Output As iFileNum Print #iFileNum, sTemp Close iFileNum 

结束小组