Bonjour à tous,
j'ai créé des liens hypertextes avec une macro pour aller dans mes
différentes feuilles de classeur, mais pour les feuilles qui ont un nom
d'onglet comportant une apostrophe ( exemple " Barre d'outils " le lien ne
marche pas, même si le nom de l'onglet est entre simple cote.
Voici la macro existante :
Sub liens()
Sheets("Sommaire").Activate
For A = 1 To 25
Cells(A + 5, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:="'" & Sheets(A).Name & "'" & "!" & "A1",
TextToDisplay:=Sheets(A).Name
Next A
End sub
Quelqu'un peut-il me corriger cette macro ?
Merci par avance
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
JB
Bonjour,
Il faut doubler les apostrophes:
Application.Substitute(Sheets(i).Name, "'", "''")
Sub liens2() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub ou si Excel2000+
Sub liens() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub
Cordialement JB
Bonjour,
Il faut doubler les apostrophes:
Application.Substitute(Sheets(i).Name, "'", "''")
Sub liens2()
Sheets("Sommaire").Activate
For i = 1 To Sheets.Count
Cells(i + 5, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'",
"''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name
Next i
End Sub
ou si Excel2000+
Sub liens()
Sheets("Sommaire").Activate
For i = 1 To Sheets.Count
Cells(i + 5, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!"
& "A1", TextToDisplay:=Sheets(i).Name
Next i
End Sub
Sub liens2() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub ou si Excel2000+
Sub liens() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub
Cordialement JB
Infogroup
Bonsoir JB et merci pour ta réponse rapide. Tout est OK Merci encore Cordialement Infogroup
-- M.Infogroup
Bonjour,
Il faut doubler les apostrophes:
Application.Substitute(Sheets(i).Name, "'", "''")
Sub liens2() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub ou si Excel2000+
Sub liens() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub
Cordialement JB
Bonsoir JB et merci pour ta réponse rapide.
Tout est OK
Merci encore
Cordialement
Infogroup
--
M.Infogroup
Bonjour,
Il faut doubler les apostrophes:
Application.Substitute(Sheets(i).Name, "'", "''")
Sub liens2()
Sheets("Sommaire").Activate
For i = 1 To Sheets.Count
Cells(i + 5, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'",
"''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name
Next i
End Sub
ou si Excel2000+
Sub liens()
Sheets("Sommaire").Activate
For i = 1 To Sheets.Count
Cells(i + 5, 1).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _
SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!"
& "A1", TextToDisplay:=Sheets(i).Name
Next i
End Sub
Bonsoir JB et merci pour ta réponse rapide. Tout est OK Merci encore Cordialement Infogroup
-- M.Infogroup
Bonjour,
Il faut doubler les apostrophes:
Application.Substitute(Sheets(i).Name, "'", "''")
Sub liens2() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Application.Substitute(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub ou si Excel2000+
Sub liens() Sheets("Sommaire").Activate For i = 1 To Sheets.Count Cells(i + 5, 1).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", _ SubAddress:="'" & Replace(Sheets(i).Name, "'", "''") & "'" & "!" & "A1", TextToDisplay:=Sheets(i).Name Next i End Sub