afficher une image en cliquant sur une cellule

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

alfazoulou

XLDnaute Occasionnel
Bonjour le forum.
je voudrais pouvoir afficher une image dans un rectangle (pour qu'elle soit toujour à la mème place) en cliquant sur une cellule, jusque là je sais faire.
Mais je voudrais dans ce meme rectangle pouvoir afficher une autre image si je clique sur une autre cellule.
autrement dit, à differentes cellules correspondent differentes images qui seront affichées dans le rectangle si on clique dessus (ou double clic, ou clic droit comme dans mon exemple ci dessous.

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Range("A9"), Target) Is Nothing Then Exit Sub
Cancel = True
ActiveSheet.Shapes("Rectangle 26").Select
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.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.UserPicture _
"C:\Documents and Settings\toto\Bureau\porte.jpg"
Range("F22").Select

If Intersect(Range("A13"), Target) Is Nothing Then Exit Sub
Cancel = True
ActiveSheet.Shapes("Rectangle 26").Select
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.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.UserPicture _
"C:\Documents and Settings\toto\Bureau\24_portegarage.jpg"
Range("F22").Select
Exit Sub
End Sub

la première partie du code fonctionne mais pas la seconde.
pouvez vous m'aider svp ?
 
Re : afficher une image en cliquant sur une cellule

Bonjour alfazoulou,

en mettant

If Intersect(Range("A9"), Target) Is Nothing Then Exit Sub

en début de code, tu dis : si ce n'est pas en A9 que l'on fait un clic droit, arrêtes tout. il n'arrive donc jamais au test de A13...

il serait peut-être plus logique de faire :

Code:
If not Intersect(Range("A9"), Target) Is Nothing Then 
Cancel = True
ActiveSheet.Shapes("Rectangle 26").Select
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.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.UserPicture _
"C:\Documents and Settings\toto\Bureau\porte.jpg"
Range("F22").Select
Elseif not Intersect(Range("A13"), Target) Is Nothing then
Cancel = True
ActiveSheet.Shapes("Rectangle 26").Select
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.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.Fill.UserPicture _
"C:\Documents and Settings\toto\Bureau\24_portegarage.jpg"
Range("F22").Select
end if

bien que ce soit sans doute simplifiable, puisque tu as de nombreuses lignes en commun pour les 2 cas...
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

A
Réponses
11
Affichages
2 K
A
Retour