LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Deleting shapes crashes for me. (Excel 97 vba)

This is code I've written quickly to find all the shapes on a sheet
that are groups, replace them with pictures and delete the groups.

Sub replace_groups()

Dim sh As Shape
Dim dShTop, dShLeft, dShHeight, dShWidth As Double
Dim lCounter, lLastShape As Long

For Each sh In ActiveSheet.Shapes
If sh.Type = msoGroup Then
With sh
dShTop = .Top
dShLeft = .Left
dShHeight = .Height
dShWidth = .Width

.Copy
End With

ActiveSheet.PasteSpecial Format:="Picture (Enhanced
Metafile)", _
Link:=False, DisplayAsIcon:=False
lLastShape = ActiveSheet.Shapes.Count

With ActiveSheet.Shapes(lLastShape)
.Top = dShTop
.Left = dShLeft
.Height = dShHeight
.Width = dShWidth
End With

End If ' shape is a group
Next sh

For lCounter = lLastShape To 1 Step -1
If ActiveSheet.Shapes(lCounter).Type = msoGroup Then
ActiveSheet.Shapes(lCounter).Select
' ActiveSheet.Shapes(lCounter).Delete
If MsgBox("Delete shape " & lCounter & "?", 292, "Deleting
shapes") _
= 6 Then ActiveSheet.Shapes(lCounter).Delete
End If
Next lCounter

End Sub


If I leave in the stupid messagebox, the program runs without
crashing. If I try to delete directly it crashes.

I would really appreciate
A: A better way to replace all of the shapes on a worksheet that are
of type msogroup with shapes of time msopicture
and/or
B: An explanation of why the code above crashes excel unless I stop
and interact with the user every time before deleting a shape.

Thanks in advance.
 
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
Excel 2007 Crashes When Deleting Column Julian Slaughter Excel Discussion (Misc queries) 0 February 4th 10 11:13 AM
excel document with shapes on it but the shapes do not print [email protected] Excel Worksheet Functions 2 October 22nd 09 06:17 PM
When drawing shapes in excel the shapes keep disappearing Tape Excel Discussion (Misc queries) 1 October 6th 06 04:23 PM
Deleting Shapes aftamath Excel Discussion (Misc queries) 5 November 5th 05 12:37 AM
How can i get more 3D shapes for Auto shapes in excel? Ajey Excel Discussion (Misc queries) 0 March 3rd 05 09:53 AM


All times are GMT +1. The time now is 10:35 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"