Clever-Excel-Forum

Normale Version: mit VBA Reihe von Schaltflächen mit 4-8 Bilder zum vergleichen (einfügen und entfer.)
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Versuche, eine Reihe von Schaltflächen zu haben, die 4-8 Bilder zum Vergleich einfügen und entfernen können.
Bin eigendlich ganz neu in VBA. Kann jemand überhaupt helfen?
Habe diesen Text im Internet gefischt....
Habe es fast fertig (meine ichSad nur) , aber ich bekomme einen Fehler im Bereich zum Entfernen von Bildern.
Wohin es geht Next picPicture bekommt eine ungültige Next-Steuervariablenreferenz, ich bin mir nicht sicher warum.

PHP-Code:
Sub picture_insert ()
    Dim picBild As Picture
    Dim blnAvailable 
As Boolean
    With worksheets 
("sheet2")
        .Unprotect Password: = "1234"
        For Each picBild In .Pictures
            
If picBild.Name "Picture Name" Then
                
'The picture already exists
                blnVorhanden = True
                Exit For
            End If
        Next picPicture
        '
only execute if picture does not yet exist
        
If blnVorhanden False Then
            With 
.Pictures.Insert ("" C: \ Temp Logo.jpg ")
                .Name = "
picture name"
                .ShapeRange.LockAspectRatio = msoFalse
                .Width = 100
                .Height = 100
                .Left = Worksheets ("
Sheet2"). Range ("A10"). Left
                .Top = Worksheets ("
Sheet2"). Range ("G42"). Top
            End With
        End If
        .Protect Password: = "
1234", DrawingObjects: = True, Contents: = True, Scenarios: = True _
            , AllowFormattingCells: = True
    End With
End Sub

Sub Image_Remove ()
    Dim picBild As Picture
    With Worksheets ("
Sheet2")
        .Unprotect Password: = "
1234"
        For Each picBild In .Pictures
            If picBild.Name = "
Picture Name" Then
                picBild.Delete
                Exit For
            End If
        Next picPicture
        .Protect Password: = "
1234", DrawingObjects: = True, Contents: = True, Scenarios: = True _
            , AllowFormattingCells: = True
    End With
End Sub 
     Ich hoffe das ich mich verständlich gemacht habe was ich bewerkstelligen möchte, bin nicht mal für das sicher Huh .

Dankbar für jede Hilfe.
Niko   78
Hallo, 19

so sollte es mal grundsätzlich funktionieren: 21

Code:
Option Explicit
Sub Image_Insert()
    Dim picBild As Picture
    Dim blnVorhanden As Boolean
    With Worksheets("Sheet2")
        .Unprotect Password:="1234"
        For Each picBild In .Pictures
            If picBild.Name = "Picture Name" Then
                'The picture already exists
                blnVorhanden = True
                Exit For
            End If
        Next picBild
        'only execute if picture does not yet exist
        If blnVorhanden = False Then
            With .Pictures.Insert("C:\Temp\Logo.jpg")
                .Name = "Picture Name"
                .ShapeRange.LockAspectRatio = msoFalse
                .Width = 100
                .Height = 100
                .Left = Worksheets("Sheet2").Range("A10").Left
                .Top = Worksheets("Sheet2").Range("G42").Top
            End With
        End If
        .Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFormattingCells:=True
    End With
End Sub
Sub Image_Remove()
    Dim picBild As Picture
    With Worksheets("Sheet2")
        .Unprotect Password:="1234"
        For Each picBild In .Pictures
            If picBild.Name = "Picture Name" Then
                picBild.Delete
                Exit For
            End If
        Next picBild
        .Protect Password:="1234", DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFormattingCells:=True
    End With
End Sub

Wenn du "Option Explicit" einsetzen würdest, dann wären dir die Fehler gleich aufgefallen. Du arbeitest mit unterschiedlichen Variablennamen "Dim picBild As Picture" und "Next picPicture". Auch bei "Sub Image_Remove()". Und "Dim blnAvailable As Boolean" - dann "blnVorhanden = True".
Vielen Dank für die schnelle Antwort, echt super! Thumps_up
Werde es nach Wochenende auf der Arbeit ausprobieren und Feedback zurückgeben
 

Danke,
 
Niko 78