macro empeche le bon fonctionnement d'une autre macro

charette63

XLDnaute Occasionnel
Bonjour a toutes et tous,

J’ai crée, via l’éditeur, une macro pour archiver un dossier. Parmi les différentes fonctions demandées à la macro, il y en a une qui « fige » les données (copier/coller spécial/valeur).
Voici cette macro

Code:
Sub archivage1()
    Call deprotegetout
    Call demasquer_onglets1
    Sheets(1).Select
    Cells.Select
      Application.CutCopyMode = False
      Selection.Copy
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("D2").Select
      ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
     With Selection.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
     End With
    Range("D4").Select
      ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
     With Selection.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
     End With
    Range("D5").Select
      ActiveCell.SpecialCells(xlCellTypeSameValidation).Select
     With Selection.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
     End With
    Sheets(Array(2, 3, 4, 5, _
        6, 7, 8, 9, 10, 11, _
        12, 13, 14, 15, 16, 17, 18, _
        19, 20, 21, 22, 23, 24, 25, _
        26, 27, 28, 29, _
        30, 31, 32, 33, 34)).Select _
        Replace:=False
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Locked = True
    Selection.FormulaHidden = True
    Range("A1").Select
   Sheets(1).Select
    Application.Dialogs(xlDialogSaveAs).Show
End Sub

J’ai une autre Macro qui change la couleurs de certaines cellules lorsqu’elles sont modifiées
La voici

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh Is Worksheets("Horaire") And Not Intersect(Range("D4:AH69"), Target) Is Nothing Then
Target.Interior.Color = vbYellow
End If
End Sub

Mon problème est lorsque j’active la macro archivage, (comme dit plus haut, elle modifie certaines valeurs dans certaines cellules) un message d’erreur apparaît :
« la methode ‘intersect’ de l’objet ‘_global’ à échoué.
La ligne "if SH Is Worksheets.........." de la macro ci-dessus est surlignée en jaune, et quand je supprime la macro un second message me dit « erreur définie par l’application ou par l’objet »

De plus, j’ai essayé la macro « archivage » en ayant remplacé la macro ci dessus par une macro similaire sans sélection de plage de cellule et là ça fonctionne
La voici :

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

If Sh Is Worksheets("Horaire") Then
Target.Interior.Color = vbYellow
End If

End Sub

Pouvez-vous m’aider ?
Est-il possible d’integrer la fonction :application.enableevents-false/true ? si oui, j’aurais besoin d’explication pour la placé correctement dans la macro

Avec mes remerciements
Cordialement
Thierry
 

Discussions similaires

Statistiques des forums

Discussions
312 252
Messages
2 086 631
Membres
103 283
dernier inscrit
SabSab