Bonjour à tous,

Je suis nouveaux sur ce forum et j'espère ben que vous allez pouvoir m'aider

J'ai une macro qui me permet d'importer des images sur une feuille excel, elle fonctionne très bien sur une feuille mais dès que je veux l'utiliser sur une autre feuille (en changeant bien sur l'appel de la feuille excel) elle ne fonctionne plus !!!

L'erreur est la suivante :
Nom : 2.JPG
Affichages : 219
Taille : 17,1 Ko

Le code s'arrête sur cette ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
Set img = ActiveSheet.DrawingObjects(ActiveSheet.Shapes.Count)
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
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
35
36
37
38
39
40
41
42
43
Sub bp_add_photo_R1()
 
 'variable select photo
        Dim fd As Object
        Dim SelectedFile As Variant
        Dim repertoire
        Dim rep As Integer
        Dim dir_photo
        Dim img
                        Worksheets("Hazard_pictures").Activate
 
                        rep = MsgBox("Add a Hazard Picture ?", vbYesNo + vquestion)
 
                        If rep = vbYes Then
 
                                                If Application.Dialogs(xlDialogInsertPicture).Show Then
                                                    dir_photo = "B4"
                                                 End If
 
                                       Set Emplacement = Worksheets("Hazard_pictures").Range(dir_photo)
                                       Set img = ActiveSheet.DrawingObjects(ActiveSheet.Shapes.Count)
 
                                            If img.ShapeRange.Width > img.ShapeRange.Height Then
                                            img.ShapeRange.Width = 210
                                            End If
                                            If img.ShapeRange.Height > 140 Then
                                            img.ShapeRange.Height = 140
                                            End If
 
                                        With img.ShapeRange
                                            .Name = "1"
                                            .LockAspectRatio = msoTrue
                                            .Left = Emplacement.Left + (Emplacement.Width - img.Width) / 2
                                            .Top = Emplacement.Top + (Emplacement.Height - img.Height) / 2
                                        End With
 
 
 
                        Else
                            MsgBox "Interrupted picture insertion"
                        End If
 
End Sub
Si vous pouvez m'aider je vous en serais reconnaissant...

Merci pour votre aide