Replacing node (1 Viewer)

dalanaaccess

New member
Local time
Today, 14:49
Joined
Feb 13, 2018
Messages
7
Hi,

This is the following XML file I have. Please help me to change node <DistributionList> to be <CompanyList> in the same XML file using VBA?

Thank you so much!

<?xml version="1.0" encoding="utf-8"?>
<DistributionLists>
<List>
<Name>Recon</Name>
<TO>John;Bob;Rob;Chris</TO>
<CC>Jane;Ashley</CC>
<BCC>Brent</BCC>
</List>
<List>
<Name>Safety Metrics</Name>
<TO>Tom;Casper</TO>
<CC>Ashley</CC>
<BCC>John</BCC>
</List>
<List>
<Name>Performance Report</Name>
<TO>Huck;Ashley</TO>
<CC>Tom;Andrew</CC>
<BCC>John;Seema</BCC>
</List>
</DistributionLists>
 

MarkK

bit cruncher
Local time
Today, 14:49
Joined
Mar 17, 2004
Messages
8,181
Since this is a complex and multi-step operation, perhaps you can say more about where you are stuck. If you need help opening a file, for instance, then I'd waste my time describing how to find and replace a substring.
See what I mean?
Mark
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:49
Joined
May 7, 2009
Messages
19,242
you just use Replace() function to change that:

Dim objFSO As Object
Dim objText As Object
Dim strContent As String

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objText = objFSO.OpenTextFile("yourXMLFullPathAndNameHere", 1)
strContent = objText.ReadAll

objText.Close
strContent = Replace(strContent, "DistributionLists>","CompanyList>")
Set objText = objFSO.OpenTextFile("yourXMLFullPathAndNameHere", 2)

objText.Write strContent

objText.Close
Set objFSO = Nothing
Set objText=Nothing
 

Users who are viewing this thread

Top Bottom