ich habe da ein Makro, welches in verschiedenen Zellen abhängig vom Inhalt ein Bild einfügt. Am Anfang des Makros sollen alle Bilder gelöscht werden, da sich die Inhalte der Zellen ständig ändern.
Code:
Sub bilder()
Dim zeile, abstand, hoehe As Integer
Dim objPicture As Picture
Dim shpShape As Shape
Dim lngRow As Long
Dim signum, pfad As String
pfad = Sheets("Einstellungen").Cells(3, 5)
For Each shpShape In ActiveSheet.Shapes
If shpShape.TopLeftCell.Rows > 25 Then shpShape.Delete
Next shpShape
signum = "C:\Unterschrift.jpg"
With Cells(39, 2)
Set objPicture = .Parent.Pictures.Insert(signum)
objPicture.Left = .Left
objPicture.Top = .Top
With objPicture
.ShapeRange.LockAspectRatio = msoTrue
.Placement = xlMoveAndSize
.PrintObject = True
.ShapeRange.Height = 45
.ShapeRange.Rotation = 0#
.ShapeRange.PictureFormat.TransparentBackground = True
.ShapeRange.PictureFormat.TransparencyColor = RGB(255, 255, 255)
End With
End With
End If
With Cells(763, 2)
Set objPicture = .Parent.Pictures.Insert(signum)
objPicture.Left = .Left
objPicture.Top = .Top
With objPicture
.ShapeRange.LockAspectRatio = msoTrue
.Placement = xlMoveAndSize
.PrintObject = True
.ShapeRange.Height = 45
.ShapeRange.Rotation = 0#
.ShapeRange.PictureFormat.TransparentBackground = True
.ShapeRange.PictureFormat.TransparencyColor = RGB(255, 255, 255)
End With
End With
End If
lngRow = 47
For zeile = 47 To 753 Step 3
If Rows(zeile - 1).EntireRow.Hidden = False Then
If Range("E" & zeile) "" Then
If Rows(zeile).rowheight Rows(zeile).rowheight = 95
End If
With Cells(lngRow, 5)
Set objPicture = .Parent.Pictures.Insert(pfad & Cells(lngRow, 5))
objPicture.Top = .Top
objPicture.Left = .Left
With objPicture
.ShapeRange.LockAspectRatio = msoTrue
.Placement = xlMoveAndSize
.PrintObject = True
.ShapeRange.Height = 90
.ShapeRange.Rotation = 0#
.ShapeRange.IncrementTop 3
.ShapeRange.IncrementLeft 3#
End With
End With
End If
End If
lngRow = lngRow + 3
Next zeile
Das Einfügen der Bilder funktioniert wunderbar. Aber mit dem löschen klappt das nicht so ganz.
Alle Bilder zwischen Zeile 47 und 753 werden gelöscht, so wie ich es möchte. Nur die beiden Bilder in Zeile 39 und 763 bleiben da. Schiebe ich die Bilder aber in den Bereich der anderen Zeilen werden sie gelöscht.
Was mache ich hier falsch? Die Bilder sind doch mit allen Attributen etc. identisch.
Vielen Dank für Eure Hilfe
Der Jens