Nom des objets insérés dans une feuille de calcul

fredannab

XLDnaute Nouveau
Bonjour,
J'ai une macro qui insere des photos (croquis de références). Une fois inséré, l'objet s'apelle shapes("123"), le numéro variant au fure et à mesure des insertions de photo. Ceci rend impossible la création d'une macroq ui ensuite supprimerai la photo (l'utilisateur sélectionne une ref, appuie sur un bouton qui fait apparâitre la photo, éventuellement la copie colle quelque part, et enfin appuirai sur un bouton qui automatiquement supprimerai la photo et mettrai les champs de sélection à) blanc.


Voici le code

Range("E18").Select
croquis_pap = ActiveCell
Dim pap_picture As String


Range("G14").Select
ActiveSheet.Pictures.Insert( _
"\\parh01-serv20\commercial\wholesale division\CATALOGUES\CATALOGUES MACROS PHOTOS\11 CPE\PAP\" & croquis_pap & ".jpg" _
).Select
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.IncrementLeft 21#
Selection.ShapeRange.IncrementTop -6.75
Selection.ShapeRange.IncrementLeft -1.5
Selection.ShapeRange.IncrementTop -18.75
Selection.Name = pap_picture

Voilà, j'ai recorded vite fait une autre macro qui consiste à sélectionner la shape et la supprimer, pour vois si apparaissait bien shapes("pap_picture").delete
Or, il me montre shapes("").delete

Comment faire pour nommer comme je veux la fameuse shape qui provient du .jpeg inséré?

Merci si quelqu'un peut m'aider... !
 

Banzai64

XLDnaute Accro
Re : Nom des objets insérés dans une feuille de calcul

Bonjour

A essayer

VB:
Sub test()
Dim Croquis_Pap As String
Dim Pap_Picture As String
Dim Pct As Object

  Croquis_Pap = Range("E18")
  Pap_Picture = "A effacer"
  
  Range("G14").Select
  Set Pct = ActiveSheet.Pictures.Insert( _
            "\\parh01-serv20\commercial\wholesale division\CATALOGUES\CATALOGUES MACROS PHOTOS\11 CPE\PAP\" & Croquis_Pap & ".jpg")
  
  With Pct
    .Name = Pap_Picture
    With .ShapeRange.Fill
      .Visible = msoFalse
      .Solid
      .Transparency = 0#
    End With
    With .ShapeRange.Line
      .Weight = 0.75
      .DashStyle = msoLineSolid
      .Style = msoLineSingle
      .Transparency = 0#
      .Visible = msoTrue
      .ForeColor.SchemeColor = 64
      .BackColor.RGB = RGB(255, 255, 255)
    End With
    With .ShapeRange
      .IncrementLeft 21#
      .IncrementTop -6.75
      .IncrementLeft -1.5
      .IncrementTop -18.75
    End With
  End With
  '
  ' Pour effacer
  '
  ActiveSheet.Shapes("A effacer").Delete

End Sub
 

fredannab

XLDnaute Nouveau
Re : Nom des objets insérés dans une feuille de calcul

Ca marche du tonnerre, merci beaucoup, j'apprecie vraiment le temps que tu y as passé !

C'est dingue, on arrive à tout faire, suffit d'avoir la bonne méthode. en fait j'apprends en faisant donc le coup de la variabvle définit comme object, ça a permis de s'en sortir.

Merci encore, vraiment!
Fred
 

Statistiques des forums

Discussions
312 105
Messages
2 085 350
Membres
102 870
dernier inscrit
Armisa