Hello everyone,
I'm trying to delete a single XML Element using powershell for an Excel.officeUI file but I'm having trouble getting it to identify the correct node.
The element looks like this:
<mso:tab id="mso_c2.3ED4DC" label="Macros" insertBeforeQ="mso:TabHome">.... and all the information about the custom ribbon I created in Excel appear all the way to </mso:tab>
It's nested in the following location:
<customUI>
<ribbon>
<tabs>
<mso:tab id="mso_c2.3ED4DC" label="Macros" insertBeforeQ="mso:TabHome">.... and all the information about the custom ribbon I created in Excel appear all the way to </mso:tab>
</tabs></ribbon</customUI>
There are other mso:tab element s with different ids but when I try the following code, it's giving me an error "the node to be removed is not a child of this node".
[xml]$xmlExcelLocal = Get-Content($localExcelFile) $CopyMSONode = $xmlExcelLocal.ImportNode($xmlExcelNet.customUI.ribbon.tabs.tab,$true) $xmlExcelLocal.customUI.ribbon.tabs.ParentNode.RemoveChild($CopyMSONode) $xmlExcelLocal.Save($localExcelFile)
I've also tried:
$RemoveMSONode = $xmlExcelLocal.customUI.ribbon.tabs.SelectNodes('//mso:tab[@id="mso_c2.3ED4DC"]') $xmlExcelLocal.customUI.ribbon.tabs.ParentNode.RemoveChild($RemoveMSONode) $xmlExcelLocal.Save($localExcelFile)
Hopefully this makes sense to someone!
Thank you :)
Alex