Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2011, 08:49 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default Delete all shapes but not the images - Possible?

I am trying to create a macro to delete lines (the length of the line varies, but, the width is always set to 0 cm) that have been added to a page, but, every variance I put in, still deletes all the shapes including pictures that I want left in.


I am using the following code:

Dim iShp As Word.Shape
For Each iShp In ActiveDocument.Shapes
With iShp
If iShp.Width = 0 Then
iShp.Delete
End If
End With
Next

For i = ActiveDocument.Shapes.Count To 1 Step -1
ActiveDocument.Shapes(i).Delete
Next i


Is there a way round this so the pictures/illustrations are left in?
Reply With Quote
  #2  
Old 12-13-2011, 02:07 AM
macropod's Avatar
macropod macropod is offline Delete all shapes but not the images - Possible? Windows 7 64bit Delete all shapes but not the images - Possible? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi AlmostFriday,

the code:
Code:
For i = ActiveDocument.Shapes.Count To 1 Step -1
ActiveDocument.Shapes(i).Delete
Next i
guarantees all shapes will be deleted. Also, your statement:
Quote:
the length of the line varies, but, the width is always set to 0 cm
doesn't make a lot of sense to me. A varying length suggests a non-0 width. Perhaps by 'length' or 'width' you meant 'height'? In any event, you might try something along the lines of:
Code:
Dim iShp As Shape
For Each iShp In ActiveDocument.Shapes
  With iShp
    If .Type = msoAutoShape Then .Delete
  End With
Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-13-2011, 04:44 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default

Thanks Macropod

I tried the code, but it still deletes the images, the images vary in size (never larger than A3) but they are always .jpg...

Quote:
Quote:
the length of the line varies, but, the width is always set to 0 cm
Quote:
doesn't make a lot of sense to me.
A varying length suggests a non-0 width. Perhaps by 'length' or 'width' you meant 'height'?
Substitute length for height, its a vertical line that goes down the side of the page to highlight an area, the wight of the line is 3 pt.

A right tricky one...
Reply With Quote
  #4  
Old 12-13-2011, 05:04 AM
macropod's Avatar
macropod macropod is offline Delete all shapes but not the images - Possible? Windows 7 64bit Delete all shapes but not the images - Possible? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi AlmostFriday,

Quote:
I tried the code, but it still deletes the images
That's odd - it should only delete Word's own autoshape objects. Of course, if the pictures are in textboxes, they'd get deleted. Are you sure you haven't got some other code in there?


Here's an alternative routine you might try:
Code:
Dim Shp As Shape
For Each Shp In ActiveDocument.Shapes
  With Shp
    If .TextFrame.TextRange.InlineShapes.Count = 0 And _
      .Type <> msoLinkedPicture And .Type <> msoPicture Then .Delete
  End With
Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-13-2011, 05:07 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default

Thanks again Macropod

But...still deletes the pictures...

The code I am using is as follows:
Code:
Dim iShp As Word.Shape
    For Each iShp In ActiveDocument.Shapes
        With iShp
         If .Type <> msoLinkedPicture And .Type <> msoPicture Then .Delete
        End With
    Next
    For i = ActiveDocument.Shapes.Count To 1 Step -1
    ActiveDocument.Shapes(i).Delete
    Next i
I thought that this would be fairly straight forward, but, I'm starting to think its an impossible one...
Reply With Quote
  #6  
Old 12-13-2011, 05:12 AM
macropod's Avatar
macropod macropod is offline Delete all shapes but not the images - Possible? Windows 7 64bit Delete all shapes but not the images - Possible? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi AlmostFriday,

As I said before:
Quote:
Originally Posted by macropod View Post
the code:
Code:
For i = ActiveDocument.Shapes.Count To 1 Step -1
ActiveDocument.Shapes(i).Delete
Next i
guarantees all shapes will be deleted.
You have to delete that code!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-13-2011, 05:18 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default

Thanks Macropod
The only thing is that it leaves some of the horizontal lines in when I delete that part of the code?
Reply With Quote
  #8  
Old 12-13-2011, 05:43 AM
macropod's Avatar
macropod macropod is offline Delete all shapes but not the images - Possible? Windows 7 64bit Delete all shapes but not the images - Possible? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Did you retry with the first version of the code I've posted?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 12-13-2011, 05:51 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Did you retry with the first version of the code I've posted?
I tried that and it had the same result, if I run the macro a few times it eventually gets rid of them all - its as if it skips some...
Reply With Quote
  #10  
Old 12-13-2011, 01:41 PM
macropod's Avatar
macropod macropod is offline Delete all shapes but not the images - Possible? Windows 7 64bit Delete all shapes but not the images - Possible? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, in that case, try:
Code:
Dim i As Long
With ActiveDocument
  For i = .Shapes.Count To 1 Step -1
    With .Shapes(i)
      If .Type = msoAutoShape Then .Delete
    End With
  Next i
End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-14-2011, 12:04 AM
AlmostFriday AlmostFriday is offline Delete all shapes but not the images - Possible? Windows XP Delete all shapes but not the images - Possible? Office 2007
Novice
Delete all shapes but not the images - Possible?
 
Join Date: Dec 2011
Posts: 8
AlmostFriday is on a distinguished road
Default

Tried and tested

MACROPOD IS A GENIUS!!!!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete all shapes but not the images - Possible? Mail Mege Images - Path Correct but Images Repeated Sonia Sosa Mail Merge 8 04-22-2011 03:05 PM
Delete all shapes but not the images - Possible? Where did map shapes go? SueK PowerPoint 1 01-20-2011 04:30 AM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
Delete all shapes but not the images - Possible? Find and add new Shapes bonani PowerPoint 1 11-26-2009 06:21 PM
My Shapes some appear some don't Jean-Paul Visio 0 03-01-2006 01:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft