Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Remove an inserted picture

The code below inserts picture if a condition is met. My question is, is
there any way to remove the picture if the condition no longer exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Remove an inserted picture

Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use .Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is, is
there any way to remove the picture if the condition no longer exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Remove an inserted picture

Is there any way to deleted the picture without knowing what sheet it is on?
The workbook has 108 worksheets and the picture could be on any one of those
sheets.


"Peter T" <peter_t@discussions wrote in message
...
Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use .Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is, is
there any way to remove the picture if the condition no longer exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Remove an inserted picture

Obviously no direct way without knowing which sheet it's on, you'd need to
loop each sheet until you found it.

It all seems rather strange but if you inserted the picture in the first
place why not do something like this

' with the insert code

myPict.topleftcell.name = "myPic"

then when you want to delete it

Dim nm As Name
On Error Resume Next
Set nm = Nothing
Set nm = ActiveWorkbook.Names("myPic")
On Error GoTo 0
If Not nm Is Nothing Then
nm.RefersToRange.Parent.Shapes("myPic").Delete
nm.Delete
Else
'
End If

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
Is there any way to deleted the picture without knowing what sheet it is
on? The workbook has 108 worksheets and the picture could be on any one of
those sheets.


"Peter T" <peter_t@discussions wrote in message
...
Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use .Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is, is
there any way to remove the picture if the condition no longer exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default Remove an inserted picture

I tried coming up with a routine which would run through each worksheet but
it it errors out if the picture does not exist on the page.



Application.ScreenUpdating = True
Application.EnableEvents = False

Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
ActiveSheet.Pictures("Auto").Delete
End With
Next n

Application.EnableEvents = True
Application.ScreenUpdating = True



"Peter T" <peter_t@discussions wrote in message
...
Obviously no direct way without knowing which sheet it's on, you'd need to
loop each sheet until you found it.

It all seems rather strange but if you inserted the picture in the first
place why not do something like this

' with the insert code

myPict.topleftcell.name = "myPic"

then when you want to delete it

Dim nm As Name
On Error Resume Next
Set nm = Nothing
Set nm = ActiveWorkbook.Names("myPic")
On Error GoTo 0
If Not nm Is Nothing Then
nm.RefersToRange.Parent.Shapes("myPic").Delete
nm.Delete
Else
'
End If

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
Is there any way to deleted the picture without knowing what sheet it is
on? The workbook has 108 worksheets and the picture could be on any one
of those sheets.


"Peter T" <peter_t@discussions wrote in message
...
Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use .Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is,
is there any way to remove the picture if the condition no longer
exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Remove an inserted picture

You could check first.

Dim n As long
Dim myPict as Picture

For n = 1 To Sheets.Count
With Sheets(n)
set mypict = nothing
on error resume next
set mypict = .Pictures("Auto")
on error goto 0

if mypict is nothing then
'not on this sheet
else
mypict.delete
'exit for 'stop looking on other sheets??????
end if
End With
Next n

"Patrick C. Simonds" wrote:

I tried coming up with a routine which would run through each worksheet but
it it errors out if the picture does not exist on the page.

Application.ScreenUpdating = True
Application.EnableEvents = False

Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
ActiveSheet.Pictures("Auto").Delete
End With
Next n

Application.EnableEvents = True
Application.ScreenUpdating = True

"Peter T" <peter_t@discussions wrote in message
...
Obviously no direct way without knowing which sheet it's on, you'd need to
loop each sheet until you found it.

It all seems rather strange but if you inserted the picture in the first
place why not do something like this

' with the insert code

myPict.topleftcell.name = "myPic"

then when you want to delete it

Dim nm As Name
On Error Resume Next
Set nm = Nothing
Set nm = ActiveWorkbook.Names("myPic")
On Error GoTo 0
If Not nm Is Nothing Then
nm.RefersToRange.Parent.Shapes("myPic").Delete
nm.Delete
Else
'
End If

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
Is there any way to deleted the picture without knowing what sheet it is
on? The workbook has 108 worksheets and the picture could be on any one
of those sheets.


"Peter T" <peter_t@discussions wrote in message
...
Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use .Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is,
is there any way to remove the picture if the condition no longer
exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub






--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Remove an inserted picture

Yet another way, just for fun

Sub test()
Dim n As Long
On Error Resume Next
Do
n = n + 1
Err.Clear
Worksheets(n).Pictures("Auto").Delete
Loop Until Err.Number = 0 Or n = Worksheets.Count
On error goto 0
End Sub

Regards,
Pete T


"Patrick C. Simonds" wrote in message
...
I tried coming up with a routine which would run through each worksheet but
it it errors out if the picture does not exist on the page.



Application.ScreenUpdating = True
Application.EnableEvents = False

Dim n As Single
For n = 1 To Sheets.Count
With Sheets(n)
ActiveSheet.Pictures("Auto").Delete
End With
Next n

Application.EnableEvents = True
Application.ScreenUpdating = True



"Peter T" <peter_t@discussions wrote in message
...
Obviously no direct way without knowing which sheet it's on, you'd need
to loop each sheet until you found it.

It all seems rather strange but if you inserted the picture in the first
place why not do something like this

' with the insert code

myPict.topleftcell.name = "myPic"

then when you want to delete it

Dim nm As Name
On Error Resume Next
Set nm = Nothing
Set nm = ActiveWorkbook.Names("myPic")
On Error GoTo 0
If Not nm Is Nothing Then
nm.RefersToRange.Parent.Shapes("myPic").Delete
nm.Delete
Else
'
End If

Regards,
Peter T

"Patrick C. Simonds" wrote in message
...
Is there any way to deleted the picture without knowing what sheet it is
on? The workbook has 108 worksheets and the picture could be on any one
of those sheets.


"Peter T" <peter_t@discussions wrote in message
...
Give the Picture a unique name when you insert it

With rng
Set myPict = .Parent.Pictures.Insert( etc
myPict.Name = "myPic"

If the condition requires it be deleted

On Error Resume next
Activesheet.Pictures("myPic").delete ' could use
.Shapes("myPic").Delete
On error goto 0 ' or resume normal error handling

(looks like you are dealing with the activesheet)

Regards,
Peter T


"Patrick C. Simonds" wrote in message
...
The code below inserts picture if a condition is met. My question is,
is there any way to remove the picture if the condition no longer
exists?


Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error


If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If


If range("F1") = "No Picture" Then GoTo NoPicture


With rng
Set myPict =
.Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Remove an inserted picture

Just to add to Peter's suggestion...

I like to use the address of the topleftcorner of the cell in the name if I know
I'm going to manipulate the picture based on its location.

with myPict
.name = "Pic_" & .topleftcell.address(0,0)
end with

Or if it uses some other criteria, give it a name that includes that criteria.

"Patrick C. Simonds" wrote:

The code below inserts picture if a condition is met. My question is, is
there any way to remove the picture if the condition no longer exists?

Sub InsertHoliday()
Dim myPict As Picture
Dim rng

On Error GoTo Error

If range("B58").Value < "" Then
Set rng = range("B18")
End If

If range("C58").Value < "" Then
Set rng = range("C18")
End If

If range("D58").Value < "" Then
Set rng = range("G18")
End If

If range("F1") = "No Picture" Then GoTo NoPicture

With rng
Set myPict = .Parent.Pictures.Insert("C:\Users\Owner\Desktop\Ne w
Years Large.gif")
myPict.Top = .Top
myPict.Left = .Left
End With

Error:

End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I associate an inserted picture with its row? [email protected] Excel Discussion (Misc queries) 1 October 22nd 09 07:22 AM
Printing the inserted picture Wildan Excel Discussion (Misc queries) 0 December 13th 06 03:10 PM
Picture inserted onto my spreadsheet will not print Jordan Excel Programming 3 August 29th 06 02:01 PM
Inserted picture name DaveJones Excel Programming 7 December 8th 05 02:36 PM
picture 34 was inserted by excel? sophy2 Excel Discussion (Misc queries) 1 October 6th 05 02:23 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"