Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50199

Macro to delete an previously inserted image

$
0
0
Hi, could someone help me with this problem please. I'm using a macro assigned to a Command Button to insert an image into an Excel worksheet, this is the code

Code:

Private Sub AddLogo_Click()
ActiveSheet.Unprotect Password:="password"
Dim fName As Variant

Range("A2").Select
fName = Application.GetOpenFilename("Picture files (*.jpg;*.gif;*.bmp), *.jpgs;*.gif;*.bmp", , _
            "Select the picture")
If fName = "False" Then Exit Sub

ActiveSheet.Pictures.Insert(fName).Select
    With Selection.ShapeRange
        .LockAspectRatio = msoFalse
        .Top = Range("A2").Top
        .Left = Range("A2").Left
        Selection.ShapeRange.Height = 25
        Selection.ShapeRange.Width = 250
        Range("A2").Select
 ActiveSheet.Protect Password:="password"
    End With
End Sub

But I now need another macro to delete the image again but not the command button (I also want to assign this new code to a command button). I've been stuggling with this for a while now and can't find anything that will work. I'd be really grateful for some help - I'm not that good on VBA but I'm trying to learn.

Many thanks, Karen

Viewing all articles
Browse latest Browse all 50199

Trending Articles