Apparently, Excel dynamically sorts the Connection.Item () array. Therefore, my modifications sent updated names at the bottom of the array. Before: FY2013Conn1, FY2013Conn2, FY2013Conn3, FY2013Conn4 After: FY2014Conn2, FY2014Conn3, FY2014Conn4, FY2014Conn1
It was hard to understand because I was dealing with 50+ connections. What I found effective, instead of trying to iterate over the entire set, only change the first element in the array.
'Connection Count cnt = ActiveWorkbook.Connections.Count While cnt > 0 'Always modify the first Item Set conn = ActiveWorkbook.Connections.Item(1) 'Mod code makes changes to Command Text modtext = conn.OLEDBConnection.Connection modtext = VBA.Replace(modtext, "_FY2013", "_FY2014") conn.OLEDBConnection.Connection = modtext 'Changes Connection Name conn.Name = VBA.Replace(conn.Name, "_FY2013", "_FY2014") 'Iterate through the cnt cnt = cnt - 1 Wend
Thanks for the help.
source share