Erreur d'exécution '91' Variable objet ou variable de bloc With non définie

Bonjour,

Je me tourne vers vous aujourd'hui car je suis confronté à un problème avec une macro Excel que j'ai créée il y a longtemps. Cela fait maintenant un jour et demi que j'essaie de résoudre ce problème, mais je n'ai pas réussi à trouver de solution.

Voici quand survient mon problème :

- Je clique sur "SAR6 extraction".

image

- Ensuite, je choisis l'option "Full month" avec les paramètres suivants :

image

- J'appuie sur "extraction" et c'est à ce moment-là que le message d'erreur suivant apparaît :

image

Cependant, ce que je ne parviens pas à comprendre, c'est que je n'avais jamais rencontré ce problème auparavant. Pourriez-vous me fournir de l'aide s'il vous plaît ?

Ensuite le débogage m'emmène ici :

ScrollHeight = Obj_product.Top + 20

Qui se trouve tout en bas de ce code

'----------------- Valeurs --------------------
For i = 2 To Balayage_labeling Step 1 'boucle pour la création des Labels

    'Produit
    contenu_produit = "  " & Worksheets("Auto capa").Cells(i, 1)
    Memoire_produit = Worksheets("Auto capa").Cells(i, 1)
    Set Obj_product = Me.Controls.Add("forms.label.1")
    With Obj_product
        .Name = "Produit" & i
        .Object.Caption = contenu_produit
        .Left = 20
        .Top = 15 * i + 35
        .Width = 235
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .BorderColor = RGB(0, 0, 0)
    End With

    Contenu_dia = Worksheets("Auto capa").Cells(i, 3)
    Memoire_dia = Worksheets("Auto capa").Cells(i, 3)
    Set Obj_dia = Me.Controls.Add("forms.label.1")
    With Obj_dia
        .Name = "Dia" & i
        .Object.Caption = Contenu_dia
        .Left = 255
        .Top = 15 * i + 35
        .Width = 20
        .Height = 15
        .FontSize = 7
        .TextAlign = 2
        .BorderStyle = 1
        .BorderColor = RGB(0, 0, 0)
    End With

    'Base
    Contenu_base = Worksheets("Auto capa").Cells(i, 2)
    Memoire_base = Worksheets("Auto capa").Cells(i, 2)
    Set Obj_base = Me.Controls.Add("forms.label.1")
    With Obj_base
        .Name = "Base" & i
        .Object.Caption = Contenu_base
        .Left = 275
        .Top = 15 * i + 35
        .Width = 25
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .TextAlign = 2
        .BorderColor = RGB(0, 0, 0)
    End With

    'Additions
    Contenu_addition = "  " & Worksheets("Auto capa").Cells(i, 4) & " " & Worksheets("Auto capa").Cells(i, 5) & " " & _
                        Worksheets("Auto capa").Cells(i, 6) & " " & Worksheets("Auto capa").Cells(i, 7) & " " & _
                        Worksheets("Auto capa").Cells(i, 8) & " " & Worksheets("Auto capa").Cells(i, 9) & " " & _
                        Worksheets("Auto capa").Cells(i, 10) & " " & Worksheets("Auto capa").Cells(i, 11) & " " & _
                        Worksheets("Auto capa").Cells(i, 12) & " " & Worksheets("Auto capa").Cells(i, 13) & " " & _
                        Worksheets("Auto capa").Cells(i, 14) & " " & Worksheets("Auto capa").Cells(i, 15) & " " & _
                        Worksheets("Auto capa").Cells(i, 16) & " " & Worksheets("Auto capa").Cells(i, 17) & " " & _
                        Worksheets("Auto capa").Cells(i, 18)

    Set Obj_addition = Me.Controls.Add("forms.label.1")
    Memoire_addition = Worksheets("Auto capa").Cells(i, 4)
    With Obj_addition
        .Name = "Additions" & i
        .Object.Caption = Contenu_addition
        .Left = 300
        .Top = 15 * i + 35
        .Width = 200
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .BorderColor = RGB(0, 0, 0)
    End With

    'Samples
    Contenu_samples = Worksheets("Auto capa").Cells(i, 19)
    Set Obj_samples = Me.Controls.Add("forms.label.1")
    With Obj_samples
        .Name = "Samples" & i
        .Object.Caption = Contenu_samples
        .Left = 500
        .Top = 15 * i + 35
        .Width = 40
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .TextAlign = 2
        .FontBold = True
        .BorderColor = RGB(0, 0, 0)
    End With

    'Ppk1
    Contenu_ppk1 = Worksheets("Auto capa").Cells(i, 22)
    Set Obj_PPK1 = Me.Controls.Add("forms.label.1")
    With Obj_PPK1
        .Name = "Ppk1_" & i
        .Object.Caption = Contenu_ppk1
        .Left = 540
        .Top = 15 * i + 35
        .Width = 30
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .TextAlign = 2
        .FontBold = True
        .BorderColor = RGB(0, 0, 0)
    End With

    'Ppk2
    Contenu_ppk2 = Worksheets("Auto capa").Cells(i, 26)
    Set Obj_PPK2 = Me.Controls.Add("forms.label.1")
    With Obj_PPK2
        .Name = "Ppk2_" & i
        .Object.Caption = Contenu_ppk2
        .Left = 570
        .Top = 15 * i + 35
        .Width = 30
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .TextAlign = 2
        .FontBold = True
        .BorderColor = RGB(0, 0, 0)
    End With

    'Ppk3
    Contenu_ppk3 = Worksheets("Auto capa").Cells(i, 30)
    Set Obj_PPK3 = Me.Controls.Add("forms.label.1")
    With Obj_PPK3
        .Name = "Ppk3_" & i
        .Object.Caption = Contenu_ppk3
        .Left = 600
        .Top = 15 * i + 35
        .Width = 30
        .Height = 15
        .FontSize = 7
        .BorderStyle = 1
        .TextAlign = 2
        .FontBold = True
        .BorderColor = RGB(0, 0, 0)
    End With

    'Score capabilité
    If Obj_PPK1 >= Results.PPKobj And Obj_PPK1 < 10 Then
        With Obj_PPK1
            .BackColor = RGB(20, 148, 20)
        End With
        ElseIf Obj_PPK1 >= Results.PPKtarget And Obj_PPK1 < Results.PPKobj Then
            With Obj_PPK1
                .BackColor = RGB(0, 255, 0)
            End With
        ElseIf Obj_PPK1 > 0 And Obj_PPK1 < Results.PPKtarget Then
            With Obj_PPK1
                .BackColor = RGB(247, 35, 12)
            End With
    End If
    If Obj_PPK2 >= Results.PPKobj And Obj_PPK2 < 10 Then
        With Obj_PPK2
            .BackColor = RGB(20, 148, 20)
        End With
        ElseIf Obj_PPK2 >= Results.PPKtarget And Obj_PPK2 < Results.PPKobj Then
            With Obj_PPK2
                .BackColor = RGB(0, 255, 0)
            End With
        ElseIf Obj_PPK2 > 0 And Obj_PPK2 < Results.PPKtarget Then
            With Obj_PPK2
                .BackColor = RGB(247, 35, 12)
            End With
    End If
    If Obj_PPK3 >= Results.PPKobj And Obj_PPK3 < 10 Then
        With Obj_PPK3
            .BackColor = RGB(20, 148, 20)
        End With
        ElseIf Obj_PPK3 >= Results.PPKtarget And Obj_PPK3 < Results.PPKobj Then
            With Obj_PPK3
                .BackColor = RGB(0, 255, 0)
            End With
        ElseIf Obj_PPK3 > 0 And Obj_PPK3 < Results.PPKtarget Then
            With Obj_PPK3
                .BackColor = RGB(247, 35, 12)
            End With
    End If

    'Blanc si vide
    If Contenu_ppk1 = "" Then
        With Obj_PPK1
            .BackColor = RGB(255, 255, 255)
        End With
    End If
    If Contenu_ppk2 = "" Then
        With Obj_PPK2
            .BackColor = RGB(255, 255, 255)
        End With
    End If
    If Contenu_ppk3 = "" Then
        With Obj_PPK3
            .BackColor = RGB(255, 255, 255)
        End With
    End If

    'Couleur si échantillons insuffisants
    If Contenu_samples < 30 Then
        With Obj_product
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_base
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_dia
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_addition
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_samples
            .BackColor = RGB(200, 200, 200)
            .ForeColor = RGB(255, 0, 0)
        End With
        With Obj_PPK1
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_PPK2
            .BackColor = RGB(200, 200, 200)
        End With
        With Obj_PPK3
            .BackColor = RGB(200, 200, 200)
        End With
    End If

    'Boutons de détail
    If Worksheets("Auto capa").Cells(i, 5) <> 0 Then
        Set Obj_button = Me.Controls.Add("forms.CommandButton.1")
        With Obj_button
            .Name = "Button" & i
            .Object.Caption = "DETAILS"
            .Left = 630
            .Top = 15 * i + 35
            .Width = 40
            .Height = 15
            .FontSize = 6
            .TabIndex = i
            .Tag = Memoire_produit & Memoire_base & Memoire_dia
        End With
        Else:
            Set Obj_button = Me.Controls.Add("forms.CommandButton.1")
        With Obj_button
            .Name = "Button" & i
            .Object.Caption = "DETAILS"
            .Left = 630
            .Top = 15 * i + 35
            .Width = 40
            .Height = 15
            .FontSize = 6
            .TabIndex = i
            .Tag = Memoire_produit & Memoire_base & Memoire_dia & Memoire_addition
        End With
    End If

    'Paramètres
    Contenu_param = Worksheets("Auto capa").Cells(i, 32)
    Set parameters_P1P2P3 = Me.Controls.Add("forms.label.1")
    With parameters_P1P2P3
        .Name = "Parameter" & i
        .Object.Caption = Contenu_param
        .Left = 680
        .Top = 15 * i + 35
        .Width = 235
        .Height = 15
        .FontSize = 9
        .BorderStyle = 0
    End With

    ReDim Preserve buttonsArray(1 To i)
    Set buttonsArray(i).CommandButtonEvents() = Obj_button

Next

ScrollHeight = Obj_product.Top + 20

Worksheets("Report").Activate
Application.ScreenUpdating = True

'ListBox1.ColumnHeads = True
'ListBox1.ColumnWidths = "10"
'ListBox1.RowSource = Worksheets("Auto capa").Range("A2:C29").Address

End Sub

Je peux vous transmettre le fichier Excel si vous avez le temps de jeter un coup d'œil. Je vous remercie d'avance et vous souhaite une excellente journée.

Cordialement,
MikaG

Bonjour,

Je ne suis pas un maitre en VBA mais je me débrouille assez bien malgré tout.

un ScrollHeight est normalement une propriété d'Objet.

La syntaxe devrait être la suivante :

Object.ScrollHeight = Obj_product.Top + 20

où "Object" est l'élément sur lequel tu appliques ton "ScrollHeight".

à moins que je ne me trompe !

Bonjour,

Tout d'abord, je te remercie pour ta réponse !

Cependant, j'ai essayé la syntaxe que tu m'as proposée, mais le même message d'erreur continue de s'afficher. Je ne parviens toujours pas à comprendre pourquoi. Ma variable est pourtant correctement définie (je pense). Du moins, je l'ai déclarée de la même manière que les autres.

Cordialement,
MikaG

Bonjour,

Ce que vous deviez préciser c'est sur quoi l'instruction "Scrollheigt" s'applique

Crdlt

Et si tu la mettais en 'commentaire ?

je n'ai pas vu à quoi pouvait servir cette instruction.

Essaye de la squizzer, pour voir.

Sinon, envoie ton fichier, il y a peut-être un autre objet dans une autre procédure.

Bonjour,

il est possible que vous ne passiez pas dans la boucle "For". La valeur de Balayage_labeling est à vérifier.

@salmanasard

S'agissant d'une procédure d'un Userform, l'objet Userform est pris par défaut. Donc :

ScrollHeight = Obj_product.Top + 20

est equivalent à

Me.ScrollHeight = Obj_product.Top + 20

Je vous remercie pour vos réponses.

Comme vous l'avez mentionné dans l'une de vos réponses, j'ai mis l'instruction en commentaire, car j'ai remarqué que cela ne servait finalement pas à grand-chose. Je vous remercie d'avoir examiné ma question, et je vous souhaite une agréable journée.

Cordialement,
MikaG

Rechercher des sujets similaires à "erreur execution variable objet bloc definie"