Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Runtime Error 13 with Worksheet.Delete
Why does the following code produce an error 13 (Excel 2007) after the sheet
is deleted and when the end function statement is executed? Public Function SheetDelete(varSheet As Variant) As Boolean ' var sheet is the sheet object to delete, not the index or name SheetDelete = varSheet.Delete End Function The sheet is deleted but the runtime error occurs. The function returns the correct value of the delete. Any thoughts would help. -- WEW |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Runtime Error 13 with Worksheet.Delete
On Oct 16, 7:31*pm, AlForester
wrote: Why does the following code produce an error 13 (Excel 2007) after the sheet is deleted and when the end function statement is executed? Public Function SheetDelete(varSheet As Variant) As Boolean * * ' var sheet is the sheet object to delete, not the index or name * * SheetDelete = varSheet.Delete End Function The sheet is deleted but the runtime error occurs. The function returns the correct value of the delete. Any thoughts would help. -- WEW I have tested your code and did not receive any errors, my thinking would be that the type mismatch error is coming from the function call hence why its getting to the bottom of the function before erroring, how are you calling the function? The other thing to note is the function is declared to return a boolean but as it just deletes the sheet then the function will return nothing. James |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Runtime Error 13 with Worksheet.Delete
Just a guess...
Maybe excel is recalculating and there's a calc event firing. I'd try: application.enableevents = false on error resume next 'in case it can't be deleted varsheet.delete if err.number < 0 then err.clear sheetdelete = false else sheetdelete = true end if on error goto 0 application.enableevents = true ====== In fact, I'd try this variation (without the .enableevents lines)--just to see if that worked. AlForester wrote: Why does the following code produce an error 13 (Excel 2007) after the sheet is deleted and when the end function statement is executed? Public Function SheetDelete(varSheet As Variant) As Boolean ' var sheet is the sheet object to delete, not the index or name SheetDelete = varSheet.Delete End Function The sheet is deleted but the runtime error occurs. The function returns the correct value of the delete. Any thoughts would help. -- WEW -- Dave Peterson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Runtime Error 13 with Worksheet.Delete
varSheet.Delete
does that returna true/false? this is a boolean function after all "AlForester" wrote: Why does the following code produce an error 13 (Excel 2007) after the sheet is deleted and when the end function statement is executed? Public Function SheetDelete(varSheet As Variant) As Boolean ' var sheet is the sheet object to delete, not the index or name SheetDelete = varSheet.Delete End Function The sheet is deleted but the runtime error occurs. The function returns the correct value of the delete. Any thoughts would help. -- WEW |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
error runtime 9: deleting a worksheet | Excel Programming | |||
Set worksheet range runtime error 1004 | Excel Programming | |||
getting runtime error when trying to delete records | Excel Programming | |||
runtime error '1004' delete Method of Range Class Failed | Excel Programming | |||
runtime error '1004' delete Method of Range Class Failed | Excel Programming |