VBA - update connection path for XML data

ezykiwi

New Member
Joined
Apr 10, 2009
Messages
26
Ive got a sheet where I have gone to the DATA table and linked in a remote xml file to bring the data into excel.. that works fine... and is displaying....

To change that data source i have to goto DATA and Connections and Modify it which is abit of a pain... so im wanting to be able to do it via VBA.... the problem is i have tried recording a macro to get the code but its not coming up with anything.

Im able to do it via xml mapping... but i want to be able to do it without the mapping *i could be dumb on this point but i dont use mapping.. i just pull in the xml into the s/s and then pivot the table of data

I have looked and stumbled over.... ActiveWorkbook.Connections("CONNECTION_NAME") but im not sure what if any code can be used in conjunction with that to change the connection .....

Any advice thoughts would be awesome.

Cheers
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi ezykiwi,

Experimenting with the object model a bit, this seems to work..

Code:
Sub ChangeXML_DataSource()
 Dim tbl As ListObject
 
 Const sNewURL As String = "C:\TEST\SourceB.xml"
 
 '--edit to the location of your data table
 Set tbl = Sheets("Sheet1").Range("A1").ListObject
 
 With tbl.XmlMap.DataBinding
   .ClearSettings
   .LoadSettings sNewURL
   .Refresh
 End With

End Sub

I haven't worked with linked XML sources, so I'll caution that this might not be a good method.
 
Upvote 0

Forum statistics

Threads
1,222,115
Messages
6,164,013
Members
451,867
Latest member
csktwyr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top