Problème macro sur Excel 2019

  1. Bonjour,
    J'ai un problème avec une macro qui fonctionne correctement sur les toutes les versions Excel antérieure à la version 2019. Sur la version 2019 une erreur 1004 s'affiche à chaque fois qu'on veut lancer la macro et apparemment l'erreur est sur la ligne "ActiveSheet.Hyperlinks.Add Anchor:=ActiveSheet.Cells(i, 3), Address:="", SubAddress:="'" & Sh1.Name & "'!A1", TextToDisplay:=Sh1.Name". Si vous pouvez m'aider svp. Merci par avanceplanning-test.xlsm
    
    Sub ONGLETS()
    
    Application.ScreenUpdating = False
    
    Dim Sh1 As Worksheet, i%
    
    i = 1
    
    Feuil.Activate
    
    Columns("C:C").ClearContents
    
    For Each Sh1 In Worksheets
    
        If Sh1.Name <> ActiveSheet.Name And  Sh1.Name <> "RECAP" Then
    
           ActiveSheet.Hyperlinks.Add Anchor:=ActiveSheet.Cells(i, 3), Address:="", SubAddress:="'" & Sh1.Name & "'!A1", TextToDisplay:=Sh1.Name
    
        i = i + 1
    
        End If
    
    Next Sh1
    
    ' Tri des suivis
    
        Range("C1:C23").Select
    
         ActiveWorkbook.Worksheets("ACCUEIL").Sort.SortFields.Clear
    
        ActiveWorkbook.Worksheets("ACCUEIL").Sort.SortFields.Add Key:=Range("C1:C23") _
    
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    
            With ActiveWorkbook.Worksheets("ACCUEIL").Sort
    
            .SetRange Range("C1:C23")
    
            .Header = xlYes
    
            .MatchCase = False
    
            .Orientation = xlTopToBottom
    
            .SortMethod = xlPinYin
    
            .Apply
    
        End With
    
    ' Mise en forme du texte
    
    ActiveSheet.Unprotect ""
    
        Range("C1:C23").Select
    
        With Selection.Font
    
            .Name = "ARIAL"
    
            .FontStyle = "Normal"
    
            .Size = 13
    
            .Strikethrough = False
    
            .Superscript = False
    
            .Subscript = False
    
            .OutlineFont = False
    
            .Shadow = False
    
            .Underline = xlUnderlineStyleSingle
    
            .ThemeColor = xlThemeColorHyperlink
    
            .TintAndShade = 0
    
            .ThemeFont = xlThemeFontNone
    
        End With
    
        Selection.Font.Underline = xlUnderlineStyleNone
    
            Range("B2").Select
    
    Application.ScreenUpdating = True
    
    ActiveSheet.Protect ""
    
    End Sub

Bonjour,

Je n'ai malheureusement pas connaissance de la version 2019 mais voici quand même un essai :

Sub ONGLETS()

Dim ws As Worksheet, i%, nomws$

Application.ScreenUpdating = False

with ActiveWorkbook.Worksheets("ACCUEIL")
    .Unprotect ""
    .Columns("C:C").ClearContents
'ajout hypertextes
    For Each ws In Worksheets
        If ws.Name <> .Name And  ws.Name <> "RECAP" Then
            i = i + 1
            nomws = iif(ws.name like "* *", "'" & ws.name & "'", ws.name)
            'nomws = ws.name
            .Cells(i, 3).Hyperlinks.Add Anchor:=.Cells(i, 3), Address:="", SubAddress:=nomws & "!A1", TextToDisplay:=nomws
        End If
    Next ws
'tri
    with .Sort
        .SortFields.Clear
        .SortFields.Add Key:=.Range("C1:C23"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        .SetRange .Range("C1:C23")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
' Mise en forme du texte
    With .Range("C1:C23").Font
        .Name = "ARIAL"
        .FontStyle = "Normal"
        .Size = 13
        .Underline = xlUnderlineStyleSingle
        .ThemeColor = xlThemeColorHyperlink
        '.Underline = xlUnderlineStyleNone
    End With
    .Protect ""
end with

Application.ScreenUpdating = True

End Sub

Cdlt,

Bonjour,

La feuille est protégée ?

Cdlt.

Bonjour Jean-Eric,

Oui, bien joué, la feuille est protégée en effet !

Je vais éditer mon code... Ce qui est bizarre, c'est qu'on puisse effacer du contenu et pas ajouter d'hypertextes...

Bonjour,

Merci beaucoup à tous et désolé de vous avoir fait perdre du temps. Effectivement je suis bête je n'ai pas remarqué la protection en bas alors qu'au début de la macro il fallait l'enlever. Merci encore et bonne continuation à tous.

Cordialement

Re,

N'oublie de remercier les intervenants des autres sites qui ont eux aussi réfléchi à ton souci (multiposte) !

Cdlt.

Mais oui j'ai remercié tout ceux qui ont répondu à ma question. Pourquoi j'ai fait une bourde !!

Rechercher des sujets similaires à "probleme macro 2019"