VBA copier/coller optionbutton / erreur de compilation

Bonjour,

je bloque sur une macro et je ne trouve pas de réponse sur les différents forum

je souhaite coder une macro qui me colle des optionbutton sur une ligne en fonction du remplissage de la première cellule de la ligne

pour le moment, j'ai codé le fait de copier/coller des optionbutton

lorsque je lance ma macro une fois, pas de problème

par contre, lorsque je relance ma macro, j'ai le message d'erreur suivant que je ne comprends pas :

"Erreur de compilation!

Bibliothèque d'objet incorrecte ou contenant des références à des définitions d'objets introuvables"

d'avance merci pour votre aide

ci dessous mon code :

Public j As Long

Public Sub ajout_OptionButton()

Static i As Integer
'Static j As Integer
Static k As Integer
'For j = 4 To 5          'ligne 4 et 5
'j = 4
For i = 1 To 2          'optionbutton1 et optionbutton2
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 3).Select 'i + 3 car optionbutton1 en colonne 4, optionbutton en colone 5
'    ActiveSheet.Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "pre_" & k + 1
        .Name = "pre_" & k + 1
        .Object.GroupName = "pre_" & k + 1
    End With

Next
For i = 3 To 4
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 3).Select
    'ActiveSheet.Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "lis_" & k + 1
        .Name = "lis_" & k + 1
        .Object.GroupName = "lis_" & k + 1
    End With
Next

For i = 5 To 6
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 4).Select
'    ActiveSheet.Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Sheets("test").Paste
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "pat_" & k + 1
        .Name = "pat_" & k + 1
        .Object.GroupName = "pat_" & k + 1
    End With
Next

For i = 7 To 8
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 5).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "tem_" & k + 1
        .Name = "tem_" & k + 1
        .Object.GroupName = "tem_" & k + 1
    End With
Next

For i = 9 To 10
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    Sheets("test").Paste
    'ActiveSheet.Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "med_" & k + 1
        .Name = "med_" & k + 1
        .Object.GroupName = "med_" & k + 1
    End With
Next

For i = 11 To 12
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
    'Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "con_" & k + 1
        .Name = "con_" & k + 1
        .Object.GroupName = "con_" & k + 1
    End With
Next

For i = 13 To 15
'ActiveSheet.Shapes("OptionButton" & i).Select
Sheets("test").Shapes("OptionButton" & i).Select
    Selection.Copy
    Cells(j + 4, i + 6).Select
    'ActiveSheet.Paste
    Sheets("test").Paste
'    Set shp = ActiveSheet.Shapes(Selection.Name)
    Set shp = Sheets("test").Shapes(Selection.Name)
    With shp.OLEFormat.Object
        .Object.Caption = "cor_" & k + 1
        .Name = "cor_" & k + 1
        .Object.GroupName = "cor_" & k + 1
    End With
Next

k = j - 3   'à la première boucle k = 1
'MsgBox j
'MsgBox k
'Next
j = j + 1
MsgBox j
End Sub

Bonsoir

Il faudrait regarder dans tes références si tu as active le OLE automation.

Outils > references

Cdt,

Bonjour,

merci pour votre réponse

je viens de vérifier et OLE automation est bien activé

cordialement

bonsoir

il faudrait publier votre fichier pour regarder svp

cdt,

Rechercher des sujets similaires à "vba copier coller optionbutton erreur compilation"