PC Review


Reply
Thread Tools Rate Thread

Code to delete shapes in copied sheets

 
 
nelly
Guest
Posts: n/a
 
      27th Jul 2009
I have a form/macro that allows users to select sheets from a workbook and
then copies these to a new workbook. Some of these sheets have shapes which
need deleting. I am having trouble with the following code so need help. The
new workbook does not yet have a name as the user saves it as what ever they
need it to be.

For i = 1 To Sheets.count
ActiveWorkbook.Sheets(i).Activate
Set myDocument = ActiveWorkbook.Sheets(i).Name
myDocument.Shapes.SelectAll
Selection.Delete
Next i

Thanks in advance
Nelly
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      27th Jul 2009
there are obviously better ways, but this is quick & simple

Sub shapekiller()

Dim ws As Worksheet
Dim sh As Shape

For Each ws In Worksheets
For Each sh In ws.Shapes
sh.Delete
Next
Next

End Sub

"nelly" <(E-Mail Removed)> wrote in message
news:67E0C701-2BAC-4125-8929-(E-Mail Removed)...
> I have a form/macro that allows users to select sheets from a workbook and
> then copies these to a new workbook. Some of these sheets have shapes
> which
> need deleting. I am having trouble with the following code so need help.
> The
> new workbook does not yet have a name as the user saves it as what ever
> they
> need it to be.
>
> For i = 1 To Sheets.count
> ActiveWorkbook.Sheets(i).Activate
> Set myDocument = ActiveWorkbook.Sheets(i).Name
> myDocument.Shapes.SelectAll
> Selection.Delete
> Next i
>
> Thanks in advance
> Nelly


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      27th Jul 2009
Nelly,

Deleting 'ALL' shapes can be dangerous, you may end up deleting things you
don't want to but if that's what you want try this but note it will delete
all shapes so try it on a test workbook

Dim sh As Shape
For i = 1 To Worksheets.Count
For Each sh In ActiveWorkbook.Sheets(i).Shapes
sh.Delete
Next
Next

Mike

"nelly" wrote:

> I have a form/macro that allows users to select sheets from a workbook and
> then copies these to a new workbook. Some of these sheets have shapes which
> need deleting. I am having trouble with the following code so need help. The
> new workbook does not yet have a name as the user saves it as what ever they
> need it to be.
>
> For i = 1 To Sheets.count
> ActiveWorkbook.Sheets(i).Activate
> Set myDocument = ActiveWorkbook.Sheets(i).Name
> myDocument.Shapes.SelectAll
> Selection.Delete
> Next i
>
> Thanks in advance
> Nelly

 
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 each time a sheet is deactivated Rick Rothstein \(MVP - VB\) Microsoft Excel Programming 2 4th Nov 2007 12:51 PM
code to delete sheets not in use based on a cell's drop down list =?Utf-8?B?a2FuZ2FzbmF0?= Microsoft Excel Worksheet Functions 2 20th Sep 2007 03:08 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Delete worksheets and the code sheets remain? Mike Microsoft Excel Programming 2 2nd Apr 2006 10:43 PM
Copied shapes are some times oblate mihai Microsoft Excel Programming 0 4th Feb 2004 08:43 AM


Features
 

Advertising
 

Newsgroups
 


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