Gruppe
Link
Bereich
Extern
Thema
Quellarbeitsmappe einer Verknüpfung wechseln
Problem
Wie kann ich über Eingaben in einer InputBox die Quellarbeitsmappe einer Verknüpfung ändern?
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: basMain
Sub LinkUmleitung()
Dim var As Variant
Dim iCounter As Integer
Dim sName As String, sPath As String, sExt As String
sPath = ThisWorkbook.Path & "\"
sExt = ".xls"
sName = InputBox( _
prompt:="Quellarbeitsmappe:", _
Default:="test2")
If sName = "" Then Exit Sub
sName = sPath & sName & sExt
var = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(var) Then
For iCounter = 1 To UBound(var)
ActiveWorkbook.ChangeLink _
Name:=var(iCounter), newname:=sName
Next iCounter
End If
End Sub