Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Error deleting worksheet (Excel 2003)


I'm getting the following error: "Run time error -2147221080:
Automation error" running an excel macro in 2003. I think the problem
is when I try to delete a worksheet with a command button on it. I
think somehow the button creates a reference to the worksheet and this
causes a problem when I delete the worksheet.

To duplicate this error add a button to the first worksheet and step
thru the following code using F8:

sub test
Worksheets(1).Delete
end sub

After deleting the worksheet I get the following message: "Can't enter
break mode at this time"

I think this is leading to the Automation error.

Any workarounds?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error deleting worksheet (Excel 2003)

Does the button that starts the delete process reside on the same
sheet that is being deleted? That could cause a problem. You can use
Application.OnTime to delete that sheet, and the code execution will
be deferred until Excel is ready to do it. E.g,

'[in the sheet's code module]
Sub Button1_Click()
Application.OnTime Now,"DeleteSheet",,True
End Sub

'[in a regular code module]
Sub DeleteSheet()
Application.DisplayAlerts = False
Worksheets(1).Delete
Application.DisplayAlerts = True
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Mon, 27 Oct 2008 13:10:19 -0700 (PDT), cr113
wrote:


I'm getting the following error: "Run time error -2147221080:
Automation error" running an excel macro in 2003. I think the problem
is when I try to delete a worksheet with a command button on it. I
think somehow the button creates a reference to the worksheet and this
causes a problem when I delete the worksheet.

To duplicate this error add a button to the first worksheet and step
thru the following code using F8:

sub test
Worksheets(1).Delete
end sub

After deleting the worksheet I get the following message: "Can't enter
break mode at this time"

I think this is leading to the Automation error.

Any workarounds?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Error deleting worksheet (Excel 2003)

On Oct 27, 4:19*pm, Chip Pearson wrote:
Does the button that starts the delete process reside on the same
sheet that is being deleted? That could cause a problem. You can use
Application.OnTime to delete that sheet, and the code execution will
be deferred until Excel is ready to do it. E.g,

'[in the sheet's code module]
Sub Button1_Click()
* * * * Application.OnTime Now,"DeleteSheet",,True
End Sub

'[in a regular code module]
Sub DeleteSheet()
* * * * Application.DisplayAlerts = False
* * * * Worksheets(1).Delete
* * * * Application.DisplayAlerts = True
End Sub


I think you're right. I think the reason I was getting an error was
because I was trying to delete a worksheet that had remaining code
left to execute. I fixed it by moving the remaining code to a code
module but it sounds like the "OnTime" method is the way to go.

Thanks!

Reply
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
Deleting Worksheet in excel = 2003 / 2007 Sandeep Excel Worksheet Functions 1 January 25th 10 03:23 AM
Excel 2003 converted to 2007 copying worksheet error MAC Excel Discussion (Misc queries) 0 September 6th 07 08:16 PM
-2147417848 Error Code - Deleting a Worksheet using VBA MSweetG222 Excel Programming 6 November 20th 06 06:30 PM
Deleting Worksheet Error James McDowell[_2_] Excel Programming 3 July 20th 05 10:53 PM
error runtime 9: deleting a worksheet [email protected] Excel Programming 4 April 7th 05 04:42 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"