Okay, I've narrowed it down more. ActiveWorkbook.Save works BEFORE "Killbutts", but ActiveWorkbook.Save immediately after "Killbutts" causes Excel to fail. So, I'm thinking "Killbutts" might be the problem, I just don't know why. If I remove Killbutts, it runs flawlessly.
Here's "Killbutts"; it's purpose is to delete some autoshape buttons on the active sheet. It seems to work well, but something's going wonky with it.BTW, Killbutts grew from this post: http://www.excelforum.com/excel-prog...-coloring.htmlSub Killbutts() 'Activate sheet to delete autoshapes. Dim GetShape As Shape For Each GetShape In ActiveSheet.Shapes GetShape.Delete Next With ActiveSheet 'Return our rows to normal Rows("1:8").RowHeight = 15 'Remove the Color and words from our range Range("C1:F7").ClearContents Range("C1:F7").Interior.ColorIndex = xlNone End With End Sub
My initial impression is that your workbook is corrupt as it keeps leaving shadow copies of itself open in the VBE (though it doesn't crash when I save it). My earlier points still apply though, and you ought to use Thisworkbook to refer to the workbook running the code, rather than hardcoding its name into the code.
Comment out the shape delete, then test it again.
Running it like this, everything works fine (except my buttons aren't deleted):Sub Killbutts() 'Activate sheet to delete autoshapes. 'Dim GetShape As Shape 'For Each GetShape In ActiveSheet.Shapes 'GetShape.Delete 'Next With ActiveSheet 'Return our rows to normal Rows("1:8").RowHeight = 15 'Remove the Color and words from our range Range("C1:F7").ClearContents Range("C1:F7").Interior.ColorIndex = xlNone End With End Sub
How about if you use:
Sub Killbutts() 'Activate sheet to delete autoshapes. Dim GetShape As Button For Each GetShape In ActiveSheet.Buttons GetShape.Delete Next GetShape With ActiveSheet 'Return our rows to normal Rows("1:8").RowHeight = 15 'Remove the Color and words from our range Range("C1:F7").ClearContents Range("C1:F7").Interior.ColorIndex = xlNone End With End Sub
That works, no Excel failure. It deletes my two buttons, but it doesn't delete the two red rectangular autoshapes I had behind my two buttons.
Try replacing the loop with:
and see if that does it. It's generally not a good idea to just delete all shapes on a sheet, especially if you have autofilters, data validation and the like on it.activesheet.drawingobjects.delete
Romper, thanks for the advice on deleting shapes. I'm not at all familiar with shapes, so this stuff is all new to me.
I changed Killbutts as you suggested, and it's doing the trick now with no hiccups. Thank you very much for helping me locate and fix the problem. I'll see if I can implement all your suggestions for tightening up my code.
Thanks,
John
Sub Killbutts() With ActiveSheet .DrawingObjects.Delete 'Return our rows to normal Rows("1:8").RowHeight = 15 'Remove the Color and words from our range Range("C1:F7").ClearContents Range("C1:F7").Interior.ColorIndex = xlNone End With End Sub
Glad to help. All good fun, isn't it?![]()
Sure. Except for all my hair falling out, a nervous giggle whenever I speak, and the twitching of the whole left side of my face, I'm having the time of my life!
Only the left side? Give it time.
Oh, and please don't forget to mark Solved. Ta.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks