InsertBefore方法:excel vba

时间:2018-07-31 12:55:34

标签: excel-vba

我具有XML结构,正在尝试将子节点添加到根元素的子节点中。我在方法之前使用插入,但获取对象不支持此属性或方法错误。下面是我的代码:

Sub GenerateXMLBodyForNewTestCreation()
    Dim requestTemplate, cookie, createPerfTestURL As String
    Dim noOfScripts, i, sample As Integer

    requestTemplate = Sheets("XMLSampleForCreatePerfTest").Range("B1").Value
    Set CreateTestXMLTemplate = CreateObject("Msxml2.DOMDocument")
    CreateTestXMLTemplate.LoadXML (requestTemplate)
    noOfScripts = Sheets("ScriptDetails").UsedRange.Rows.Count

    Set root = CreateTestXMLTemplate.DocumentElement
    Set root1 = CreateTestXMLTemplate.SelectNodes("//Test/Content/Groups/Group")(0)

    For i = 2 To noOfScripts
        Set y = root1.CloneNode(True)
        sample = root.InsertBefore(y, root1(0))
    Next i

    CreateTestXMLTemplate.Save ("C:\Users\rrayudu\Desktop\XMLBody.xml")
End Sub

这可能是一个愚蠢的错误,但正在努力使其正常运行。请帮忙。

0 个答案:

没有答案