I have a subroutine that looks in multiple XML files and tries to remove an XML attribute:
I am getting the following error in the following line:
Runtime error ‘91’:
Object variable or With block variable not set.
I’m unsure exactly what I am doing wrong.
Here’s a sample of the XML file:
My ultimate objective is to complete remove all references to the following pattern attribute including its values:
Example before :
Example after :
Any help in pinpointing the issue in my code would be much appreciated!
Code:
Sub ReplaceStringInFile()
Dim d As MSXML2.DOMDocument60
Dim i As MSXML2.IXMLDOMNodeList
Dim n As MSXML2.IXMLDOMNode
Set d = New MSXML2.DOMDocument60
Const sSearchString As String = "C:\Users\Shawn\Desktop\GD test\*.xml"
Dim sBuf As String
Dim sTemp As String
Dim iFileNum As Integer
Dim sFileName As String
Dim sFilePath As String
sFileName = Dir(sSearchString)
Do While sFileName <> ""
sFilePath = "C:\Users\Shawn\Desktop\GD test\" & sFileName 'Get full path to file
iFileNum = FreeFile
sTemp = "" 'Clear sTemp
Open sFilePath For Input As iFileNum
d.Load sFilePath
Set i = d.SelectNodes("//@pattern")
For Each n In i
Do Until EOF(iFileNum)
Line Input #iFileNum, sBuf
sTemp = sTemp & sBuf & vbCrLf
Loop
Debug.Print n.Text
Next n
Close iFileNum
sTemp = Replace(sTemp, n.Text, "")
iFileNum = FreeFile
Open sFilePath For Output As iFileNum
Print #iFileNum, sTemp
Close iFileNum
sFileName = Dir() 'Get the next file
Loop
End Sub
Code:
sTemp = Replace(sTemp, n.Text, "")
Object variable or With block variable not set.
I’m unsure exactly what I am doing wrong.
Here’s a sample of the XML file:
HTML:
<?xml version="1.0"?>
<report useStyleVersion="1" interactivePageBreakByFrame="true" ignoreFilterContext="false" expressionLocale="fr-fr" xmlns="http://developer.cognos.com/schemas/report/8.0/">
<!--RSU-SPC-0093 La spécification de rapport a été mise à niveau de {originalNS} à {destNS} le 5-12-2012. 8:22:16-->
<modelPath>/content/package[@name='LG - RECEVABLES.CAT']/model[last()]</modelPath>
<listColumn>
<listColumnBody>
<contents>
<style>
<CSS value="border-top-style:none;border-right-style:none;border-bottom-style:none;border-left-style:none;font-family:'Arial';font-weight:normal;font-size:6pt;text-align:center;vertical-align:top;white-space:nowrap"/>
<dataFormat>
<numberFormat pattern="####/##/##;-####/##/##"/>
</dataFormat>
</style>
</contents>
<listColumnRowSpan refDataItem="No de facture"/>
</listColumnBody>
</listColumn>
<contents>
<textItem>
<dataSource>
<dataItemValue refDataItem="Total (Montant de la facture (Can$)) No.1"/>
</dataSource>
<style>
<dataFormat>
<numberFormat pattern="$#,##0.00;-$#,##0.00"/>
</dataFormat>
</style>
</textItem>
</contents>
<reportName>LEG - Age des comptes à recevoir - Financier avec GL.imr</reportName>
</report>
My ultimate objective is to complete remove all references to the following pattern attribute including its values:
Example before :
Example after :
Any help in pinpointing the issue in my code would be much appreciated!
Last edited: