PC Review


Reply
Thread Tools Rate Thread

Code to delete shapes each time a sheet is deactivated

 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      3rd Nov 2007
Just a guess.... shouldn't you be using the Sh object argument from the
SheetDeactivate event call rather than the ActiveSheet object in your code?

Rick


"DlgomesBR" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Please, someone help me in this problem:
>
> I have a workbook with several sheets. In each sheet a have a lot of
> floating shapes created dinammicaly each time the sheet is activated. I
> need a code that each time I leave the active sheet, the shapes could be
> deleted before the new sheet is activated. If I don't do this way, my
> workbook is getting very large (currently 20MB). I am using a code below,
> but it is deleting shapes in the new sheet and not in the sheet I was on.
>
> Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
> Dim myshape As Shape, myrange As Range
> Set myrange = ActiveSheet.Range(Cells(Range("intervalo1up").Row + 1,
> 5), Cells(Range("UltimaCelula").Row, 5))
> For Each myshape In ActiveSheet.Shapes
> If Intersect(myshape.TopLeftCell, myrange) Is Nothing Then
> 'do nothing
> Else
> myshape.Delete
> End If
> Next myshape
> End Sub


 
Reply With Quote
 
 
 
 
DlgomesBR
Guest
Posts: n/a
 
      3rd Nov 2007
Please, someone help me in this problem:

I have a workbook with several sheets. In each sheet a have a lot of
floating shapes created dinammicaly each time the sheet is activated. I need
a code that each time I leave the active sheet, the shapes could be deleted
before the new sheet is activated. If I don't do this way, my workbook is
getting very large (currently 20MB). I am using a code below, but it is
deleting shapes in the new sheet and not in the sheet I was on.

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Dim myshape As Shape, myrange As Range
Set myrange = ActiveSheet.Range(Cells(Range("intervalo1up").Row + 1, 5),
Cells(Range("UltimaCelula").Row, 5))
For Each myshape In ActiveSheet.Shapes
If Intersect(myshape.TopLeftCell, myrange) Is Nothing Then
'do nothing
Else
myshape.Delete
End If
Next myshape
End Sub

 
Reply With Quote
 
Mike Fogleman
Guest
Posts: n/a
 
      4th Nov 2007
I agree. Change ActiveSheet to Sh.
The deactivated sheet = Sh
The new sheet = ActiveSheet, so it gets erased.
Mike F
"Rick Rothstein (MVP - VB)" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> Just a guess.... shouldn't you be using the Sh object argument from the
> SheetDeactivate event call rather than the ActiveSheet object in your
> code?
>
> Rick
>
>
> "DlgomesBR" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Please, someone help me in this problem:
>>
>> I have a workbook with several sheets. In each sheet a have a lot of
>> floating shapes created dinammicaly each time the sheet is activated. I
>> need a code that each time I leave the active sheet, the shapes could be
>> deleted before the new sheet is activated. If I don't do this way, my
>> workbook is getting very large (currently 20MB). I am using a code below,
>> but it is deleting shapes in the new sheet and not in the sheet I was on.
>>
>> Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
>> Dim myshape As Shape, myrange As Range
>> Set myrange = ActiveSheet.Range(Cells(Range("intervalo1up").Row + 1,
>> 5), Cells(Range("UltimaCelula").Row, 5))
>> For Each myshape In ActiveSheet.Shapes
>> If Intersect(myshape.TopLeftCell, myrange) Is Nothing Then
>> 'do nothing
>> Else
>> myshape.Delete
>> End If
>> Next myshape
>> 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
Code to delete shapes in copied sheets nelly Microsoft Excel Programming 2 27th Jul 2009 02:25 PM
Execute Codes after Sheet Deactivated Please Help Microsoft Excel Programming 7 14th May 2009 07:30 PM
How to capture Delete key for Shapes on Excel Sheet MutatedBrain Microsoft Excel Programming 0 10th Apr 2008 10:37 PM
Adding Shapes: Position changes when running code a second time - Why? Richard Buttrey Microsoft Excel Programming 3 21st Feb 2008 12:20 PM
Delete data in a linked Excel sheet using Access code or seql delete Rocky Microsoft Access External Data 9 26th Jun 2005 12:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.