Lien hypertexte en VBA
a
Bonjour le forum,
J'ai une macro qui me permet d'insèrer automatiquement des onglets lorsqu'on rentre des caractères dans une cellule. Cet onglet prend le nom de cette chaîne de carctères.
Ce que je souhaite faire, c'est de créer un lien hypertexte entre l'onglet et son nom dans la page de garde. J'ai essayé une macro mais qui ne fonctionne pas:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim I As Long, Sh As Worksheet, Teste As Boolean, Cell As String
If Target.Column = 2 And Target.Count = 1 Then
If Target.Value <> "" Then
If Worksheets.Count > 2 Then
For I = 3 To Sheets.Count
If Target.Value > Sheets(I - 1).Name And Target.Value < Sheets(I).Name Then
Sheets("Modèle").Copy before:=Sheets(I)
ActiveSheet.Name = Target.Value
Exit For
ElseIf Target.Value < Sheets(3).Name Then
Sheets("Modèle").Copy before:=Sheets(3)
ActiveSheet.Name = Target.Value
Exit For
ElseIf Target.Value > Sheets(Sheets.Count).Name Then
Sheets("Modèle").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Target.Value
Exit For
End If
Next I
ActiveSheet.Name = Target.Value
End If
End If
Sheets("Sommaire").Select
Cell = Target.Value
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
"'Cell'!A1", TextToDisplay:="Cell"
End If
End Sub
Savez-vous comment faire ?
Merci !
Bonjour,
à toi de jouer, copie/colles ce code en remplacement du tien.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim I As Long, Sh As Worksheet, Teste As Boolean, Cell As String
If Target.Column = 2 And Target.Count = 1 Then
If Target.Value <> "" Then
If Worksheets.Count > 2 Then
king = Target.Value
For I = 3 To Sheets.Count
If Target.Value > Sheets(I - 1).Name And Target.Value < Sheets(I).Name Then
king = Target.Value
Sheets("Modèle").Copy before:=Sheets(I)
ActiveSheet.Name = king
Exit For
ElseIf Target.Value < Sheets(3).Name Then
king = Target.Value
Sheets("Modèle").Copy before:=Sheets(3)
ActiveSheet.Name = king
Exit For
ElseIf Target.Value > Sheets(Sheets.Count).Name Then
king = Target.Value
Sheets("Modèle").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = king
Exit For
End If
Next I
End If
End If
Sheets("Sommaire").Select
Cell = king & "!a1"
ActiveCell.Offset(-1, 0).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
Cell, TextToDisplay:=king
End If
End Sub
a
Bonjour kingfadhel,
C'est top, merci beaucoup pour ton aide
Bonne soirée et @+ !