ich habe den folgenden Code mit Hilfe vom Forum (an dickes Dankeschön an Sepp) hier erstellt und die letzten Tage klappte auch alles gut, d.h. das entsprechende Bild wurde angeklickt, wenn man auf einen Titel in Spalte C geklickt hat und ein Bild mit gleichem Titel abgespeichert war.
Soweit, so gut und auch die Message Box erscheint korrekt, wenn man auf einen Titel in Spalte C klickt, zu dem kein Bild gespeichert ist.
Was jetzt plötzlich nicht mehr klappt, ist, dass ein zuvor angezeigtes Bild automatisch wieder verschwindet, wenn man irgendwo außerhalb von Spalte C klickt.
Habe ich hier einen Fehler im Code oder kann es sein, dass diese Funktion von einer anderen gestört wird ?
Code neu:
Option Explicit
Const imagePath As String = "C:\Users\Notebook\Desktop\My Documents\Bilder\" 'Image saving location
Const MaxWidth As Long = 270 'Maximum width for images
Const MaxHeight As Long = 210 'Maximum height for images
Const PosLeft As Long = 685 'Image location from left
Const PosTop As Long = 137 'Image location from top
Private objImg As Object
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Action 1: displays matching image when clicking on corresponding entry in column C
' Action 2: deletes displayed image if mouse click elsewhere than column C
Dim dblWidth As Double, dblHeight As Double
Dim strFile As String
If Not objImg Is Nothing Then objImg.Visible = False
DoEvents
If Target.Column = 3 And Target.Count = 1 Then
If Target "" Then
strFile = imagePath & IIf(Right(imagePath, 1) "\", "\", "") & Target.Value & ".jpg"
strFile = Replace(Replace(strFile, vbLf, ""), vbCrLf, "")
If Dir(strFile) "" Then
On Error Resume Next
If objImg Is Nothing Then Set objImg = Me.OLEObjects("imageContainer")
On Error GoTo 0
If objImg Is Nothing Then createImageContainer
With objImg
.Object.AutoSize = True
.Object.Picture = LoadPicture(strFile)
.Top = ActiveWindow.VisibleRange.Top + PosTop
.Left = PosLeft
If .Height > MaxHeight Or .Width > MaxWidth Then
.Object.AutoSize = False
dblWidth = MaxWidth / .Width
dblHeight = MaxHeight / .Height
If dblWidth
Private Sub createImageContainer()
Set objImg = Me.OLEObjects.Add(ClassType:="Forms.Image.1", Link:=False, _
DisplayAsIcon:=False, Left:=0, Top:=0, Width:=0, Height:=0)
With objImg
.Visible = False
.Object.PictureSizeMode = 1
.Name = "imageContainer"
End With
End Sub
Hoffe, Ihr könnt mir weiterhelfen ! :-)LG und vielen Dank Euch im Voraus,
Jenny