Ändern Sie den vorhandenen Excel-Verbindungsnamen in VBA
Ich muss den Verbindungsnamen der SQL-Verbindung einer Excel-Arbeitsmappe aktualisieren. Das ist mein Versuch. Ich konnte die Verbindungszeichenfolge und den Befehlstext ändern, indem ich eine Standardersetzung durchführte.
Sub ConnectionString_modify()
Dim i As Long
Dim cnt As Long
Dim modtext As String
Dim modrange As String
'Grab nummber of workbook connections
cnt = ActiveWorkbook.Connections.Count
For i = 1 To cnt
'Changes to Connection string --This works
modtext = ActiveWorkbook.Connections.Item(i).OLEDBConnection.Connection
modtext = VBA.Replace(modtext, "_FY2013", "_FY2014")
ActiveWorkbook.Connections.Item(i).OLEDBConnection.Connection = modtext
'Changes Connection Name
modname = ActiveWorkbook.Connections.Item(i).Name
modname = VBA.Replace(modname, "_FY2013", "_FY2014")
ActiveWorkbook.Connections.Item(i).Name = modname
Next i
End sub
Jede Hilfe wäre toll. Vielen Dank.