PC Review


Reply
Thread Tools Rate Thread

Deleting images in Excel document

 
 
twlove@ontuet.com
Guest
Posts: n/a
 
      27th Mar 2007
Here's my dilemma: I have a worksheet which on the click of 'Command
Button1' unprotects the worksheet, inserts a desired image into a
group of merged cells identified as cell L43 and then reprotects the
worksheet. I then have a second command button (Command Button2) that
when clicked unprotects the worksheet, removes the image from this
same group of cells and then reprotects the worksheet. Unfortunately,
when I click this Command2 button, it not only removes the image in
cell L43, it also removes every other image in the worksheet. I only
want the images in cell L43 to be removed. Any help would be
appreciated! Here's the Command2 button code:


Private Sub CommandButton2_Click()

Application.ActiveSheet.Unprotect "password"

For Each Picture In Pictures

'ActiveSheet.Pictures.Delete
'Debug.Print Picture.Name

If Left(Picture.Name, 7) = "Picture" Then

Picture.Delete

End If

Next

Application.ActiveSheet.Protect "password"

End Sub

 
Reply With Quote
 
 
 
 
JE McGimpsey
Guest
Posts: n/a
 
      27th Mar 2007
One way:

Private Sub CommandButton2_Click()
Dim oPic As Picture
With Application.ActiveSheet
.Unprotect "password"
For Each oPic In .Pictures
If oPic.TopLeftCell.Address(False, False) = "L43" Then _
oPic.Delete
Next oPic
.Protect "password"
End With
End Sub


In article <(E-Mail Removed)>,
(E-Mail Removed) wrote:

> Here's my dilemma: I have a worksheet which on the click of 'Command
> Button1' unprotects the worksheet, inserts a desired image into a
> group of merged cells identified as cell L43 and then reprotects the
> worksheet. I then have a second command button (Command Button2) that
> when clicked unprotects the worksheet, removes the image from this
> same group of cells and then reprotects the worksheet. Unfortunately,
> when I click this Command2 button, it not only removes the image in
> cell L43, it also removes every other image in the worksheet. I only
> want the images in cell L43 to be removed. Any help would be
> appreciated! Here's the Command2 button code:
>
>
> Private Sub CommandButton2_Click()
>
> Application.ActiveSheet.Unprotect "password"
>
> For Each Picture In Pictures
>
> 'ActiveSheet.Pictures.Delete
> 'Debug.Print Picture.Name
>
> If Left(Picture.Name, 7) = "Picture" Then
>
> Picture.Delete
>
> End If
>
> Next
>
> Application.ActiveSheet.Protect "password"
>
> End Sub

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      27th Mar 2007
Pictures are not "in cell", so the easiest way is to use the shapes name.
You can set this when you insert the picture.
If you have other control on the WS that you wish to keep, check what the
shape is before deleting.

Private Sub CommandButton1_Click()
ActiveSheet.Shapes("PicToDelete").Delete
End Sub

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Here's my dilemma: I have a worksheet which on the click of 'Command
> Button1' unprotects the worksheet, inserts a desired image into a
> group of merged cells identified as cell L43 and then reprotects the
> worksheet. I then have a second command button (Command Button2) that
> when clicked unprotects the worksheet, removes the image from this
> same group of cells and then reprotects the worksheet. Unfortunately,
> when I click this Command2 button, it not only removes the image in
> cell L43, it also removes every other image in the worksheet. I only
> want the images in cell L43 to be removed. Any help would be
> appreciated! Here's the Command2 button code:
>
>
> Private Sub CommandButton2_Click()
>
> Application.ActiveSheet.Unprotect "password"
>
> For Each Picture In Pictures
>
> 'ActiveSheet.Pictures.Delete
> 'Debug.Print Picture.Name
>
> If Left(Picture.Name, 7) = "Picture" Then
>
> Picture.Delete
>
> End If
>
> Next
>
> Application.ActiveSheet.Protect "password"
>
> End Sub
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting selected images from Excel worksheet Tom Microsoft Excel Programming 0 17th Jan 2010 08:39 PM
Excel deleting some numbers from an excel document Seth Microsoft Excel New Users 1 6th Feb 2008 04:55 PM
some images in excel document print inversed =?Utf-8?B?Sm9obm5pZVY=?= Microsoft Excel Misc 0 13th Jan 2005 02:27 AM
Putting images in an excel document =?Utf-8?B?R3VpbGhlcm1lIE1hcnRpbnM=?= Microsoft ASP .NET 1 4th Oct 2004 06:44 PM
Find images in a Excel document.. How !! =?Utf-8?B?TE5Ib2NrZXk=?= Microsoft Excel Programming 1 10th Feb 2004 05:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:11 AM.