PC Review


Reply
Thread Tools Rate Thread

-2147417848 Error Code - Deleting a Worksheet using VBA

 
 
=?Utf-8?B?TVN3ZWV0RzIyMg==?=
Guest
Posts: n/a
 
      19th Nov 2006
I received a -21474147848 error code (descr: method of 'Delete' of object
'_Worksheet' failed) when deleting a worksheet (using vba). The vba code is
held in a .xla file. This error issue was only occurring when I used a
particular workbook. I have no issues performing the same actions in a
different .xls workbook.

I don't know if I solved the issue or just delayed it, but this is what I
did...

I modified the .xla code to 1. set the workbook calculation status to
Manual, 2. performed the delete worksheet code and then 3. returned the
workbook calcuation to Automatic.

Comments?

Thx
MSweetG222

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      19th Nov 2006
Are you sure that you got the error message number right? The value you
provide causes an overflow on a Long data type, and system error messages
are always Long data types.

You can normally retrieve the exact error text associated with a system
error number using the GetSystemErrorMessageText function described on
http://www.cpearson.com/excel/FormatMessage.htm

This procedure, however, requires a Long data type for the error number, and
your error number is not a Long.

All that said, it sounds to me like you have the structure of the workbook
protected. Go to the Tools menu, choose Protection, and select UnProtect
Workbook. Supply the appropriate password if prompted.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)


"MSweetG222" <(E-Mail Removed)> wrote in message
newsF4175AF-2C8A-4118-BD4F-(E-Mail Removed)...
>I received a -21474147848 error code (descr: method of 'Delete' of object
> '_Worksheet' failed) when deleting a worksheet (using vba). The vba code
> is
> held in a .xla file. This error issue was only occurring when I used a
> particular workbook. I have no issues performing the same actions in a
> different .xls workbook.
>
> I don't know if I solved the issue or just delayed it, but this is what I
> did...
>
> I modified the .xla code to 1. set the workbook calculation status to
> Manual, 2. performed the delete worksheet code and then 3. returned the
> workbook calcuation to Automatic.
>
> Comments?
>
> Thx
> MSweetG222
>



 
Reply With Quote
 
=?Utf-8?B?TVN3ZWV0RzIyMg==?=
Guest
Posts: n/a
 
      19th Nov 2006
Chip - here is the error ... -2147417848 Automation error (I cut and pasted
from the immediate window, ie: err.number & err.description)

Here is what I receive when I run your procedure...
"The object invoked has disconnected from its clients. "

The line of code that it was received on ...
Sheets(sWorksheet).Delete
where sWorksheet is a sheet name

Is that information helpful?

Thx
MSweetG222



"Chip Pearson" wrote:

> Are you sure that you got the error message number right? The value you
> provide causes an overflow on a Long data type, and system error messages
> are always Long data types.
>
> You can normally retrieve the exact error text associated with a system
> error number using the GetSystemErrorMessageText function described on
> http://www.cpearson.com/excel/FormatMessage.htm
>
> This procedure, however, requires a Long data type for the error number, and
> your error number is not a Long.
>
> All that said, it sounds to me like you have the structure of the workbook
> protected. Go to the Tools menu, choose Protection, and select UnProtect
> Workbook. Supply the appropriate password if prompted.
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on the web site)
>
>
> "MSweetG222" <(E-Mail Removed)> wrote in message
> newsF4175AF-2C8A-4118-BD4F-(E-Mail Removed)...
> >I received a -21474147848 error code (descr: method of 'Delete' of object
> > '_Worksheet' failed) when deleting a worksheet (using vba). The vba code
> > is
> > held in a .xla file. This error issue was only occurring when I used a
> > particular workbook. I have no issues performing the same actions in a
> > different .xls workbook.
> >
> > I don't know if I solved the issue or just delayed it, but this is what I
> > did...
> >
> > I modified the .xla code to 1. set the workbook calculation status to
> > Manual, 2. performed the delete worksheet code and then 3. returned the
> > workbook calcuation to Automatic.
> >
> > Comments?
> >
> > Thx
> > MSweetG222
> >

>
>
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      20th Nov 2006
You usually receive an "Object Disconnected" error when you attempt to use a
variable that refers to an object that has been deleted. See
http://www.cpearson.com/excel/ConnectedObject.htm for more information about
disconnected variables.

For example, you can get a disconnect error with

Dim WS As Worksheet
Set WS = Worksheets(2)
Application.DisplayAlerts = False
Worksheets(2).Delete
Application.DisplayAlerts = True
Debug.Print WS.Name

Here, WS no longer refers to an existing worksheet (it got deleted) so
you'll a disconnect error (WS does not automatically get set to Nothing)..

But this doesn't seem to make sense in the code you posted. Is sWorksheet a
String variable? Does the sheet named in the sWorksheet variable exist in
the ActiveWorkbook (which may not be the same as the workbook containing the
code)? Is the workbook protected?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email on the web site)



"MSweetG222" <(E-Mail Removed)> wrote in message
news:8C8B19FC-7A0D-4796-BECF-(E-Mail Removed)...
> Chip - here is the error ... -2147417848 Automation error (I cut and
> pasted
> from the immediate window, ie: err.number & err.description)
>
> Here is what I receive when I run your procedure...
> "The object invoked has disconnected from its clients. "
>
> The line of code that it was received on ...
> Sheets(sWorksheet).Delete
> where sWorksheet is a sheet name
>
> Is that information helpful?
>
> Thx
> MSweetG222
>
>
>
> "Chip Pearson" wrote:
>
>> Are you sure that you got the error message number right? The value you
>> provide causes an overflow on a Long data type, and system error messages
>> are always Long data types.
>>
>> You can normally retrieve the exact error text associated with a system
>> error number using the GetSystemErrorMessageText function described on
>> http://www.cpearson.com/excel/FormatMessage.htm
>>
>> This procedure, however, requires a Long data type for the error number,
>> and
>> your error number is not a Long.
>>
>> All that said, it sounds to me like you have the structure of the
>> workbook
>> protected. Go to the Tools menu, choose Protection, and select UnProtect
>> Workbook. Supply the appropriate password if prompted.
>>
>>
>> --
>> Cordially,
>> Chip Pearson
>> Microsoft MVP - Excel
>> Pearson Software Consulting, LLC
>> www.cpearson.com
>> (email on the web site)
>>
>>
>> "MSweetG222" <(E-Mail Removed)> wrote in message
>> newsF4175AF-2C8A-4118-BD4F-(E-Mail Removed)...
>> >I received a -21474147848 error code (descr: method of 'Delete' of
>> >object
>> > '_Worksheet' failed) when deleting a worksheet (using vba). The vba
>> > code
>> > is
>> > held in a .xla file. This error issue was only occurring when I used a
>> > particular workbook. I have no issues performing the same actions in
>> > a
>> > different .xls workbook.
>> >
>> > I don't know if I solved the issue or just delayed it, but this is what
>> > I
>> > did...
>> >
>> > I modified the .xla code to 1. set the workbook calculation status to
>> > Manual, 2. performed the delete worksheet code and then 3. returned the
>> > workbook calcuation to Automatic.
>> >
>> > Comments?
>> >
>> > Thx
>> > MSweetG222
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TVN3ZWV0RzIyMg==?=
Guest
Posts: n/a
 
      20th Nov 2006
Chip, Thank you for your response.

sWorksheet is a string. The worksheet to be deleted is in another workbook
and for this particular workbook, the worksheet does not exist. (For other
workbooks, it does exist) and the workbook is not protected.

Is there a "test" I need to run to check to see if the worksheet exists
before I delete?

Again, thanks for any assistance you can give me.

Thx
MSweetG222



"Chip Pearson" wrote:

> You usually receive an "Object Disconnected" error when you attempt to use a
> variable that refers to an object that has been deleted. See
> http://www.cpearson.com/excel/ConnectedObject.htm for more information about
> disconnected variables.
>
> For example, you can get a disconnect error with
>
> Dim WS As Worksheet
> Set WS = Worksheets(2)
> Application.DisplayAlerts = False
> Worksheets(2).Delete
> Application.DisplayAlerts = True
> Debug.Print WS.Name
>
> Here, WS no longer refers to an existing worksheet (it got deleted) so
> you'll a disconnect error (WS does not automatically get set to Nothing)..
>
> But this doesn't seem to make sense in the code you posted. Is sWorksheet a
> String variable? Does the sheet named in the sWorksheet variable exist in
> the ActiveWorkbook (which may not be the same as the workbook containing the
> code)? Is the workbook protected?
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on the web site)
>
>
>
> "MSweetG222" <(E-Mail Removed)> wrote in message
> news:8C8B19FC-7A0D-4796-BECF-(E-Mail Removed)...
> > Chip - here is the error ... -2147417848 Automation error (I cut and
> > pasted
> > from the immediate window, ie: err.number & err.description)
> >
> > Here is what I receive when I run your procedure...
> > "The object invoked has disconnected from its clients. "
> >
> > The line of code that it was received on ...
> > Sheets(sWorksheet).Delete
> > where sWorksheet is a sheet name
> >
> > Is that information helpful?
> >
> > Thx
> > MSweetG222
> >
> >
> >
> > "Chip Pearson" wrote:
> >
> >> Are you sure that you got the error message number right? The value you
> >> provide causes an overflow on a Long data type, and system error messages
> >> are always Long data types.
> >>
> >> You can normally retrieve the exact error text associated with a system
> >> error number using the GetSystemErrorMessageText function described on
> >> http://www.cpearson.com/excel/FormatMessage.htm
> >>
> >> This procedure, however, requires a Long data type for the error number,
> >> and
> >> your error number is not a Long.
> >>
> >> All that said, it sounds to me like you have the structure of the
> >> workbook
> >> protected. Go to the Tools menu, choose Protection, and select UnProtect
> >> Workbook. Supply the appropriate password if prompted.
> >>
> >>
> >> --
> >> Cordially,
> >> Chip Pearson
> >> Microsoft MVP - Excel
> >> Pearson Software Consulting, LLC
> >> www.cpearson.com
> >> (email on the web site)
> >>
> >>
> >> "MSweetG222" <(E-Mail Removed)> wrote in message
> >> newsF4175AF-2C8A-4118-BD4F-(E-Mail Removed)...
> >> >I received a -21474147848 error code (descr: method of 'Delete' of
> >> >object
> >> > '_Worksheet' failed) when deleting a worksheet (using vba). The vba
> >> > code
> >> > is
> >> > held in a .xla file. This error issue was only occurring when I used a
> >> > particular workbook. I have no issues performing the same actions in
> >> > a
> >> > different .xls workbook.
> >> >
> >> > I don't know if I solved the issue or just delayed it, but this is what
> >> > I
> >> > did...
> >> >
> >> > I modified the .xla code to 1. set the workbook calculation status to
> >> > Manual, 2. performed the delete worksheet code and then 3. returned the
> >> > workbook calcuation to Automatic.
> >> >
> >> > Comments?
> >> >
> >> > Thx
> >> > MSweetG222
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      20th Nov 2006
I stole this from Chip:

Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) > 0)
End Function

'and you can use it like:
....
if worksheetexists("myname",activeworkbook) then

MSweetG222 wrote:
>
> Chip, Thank you for your response.
>
> sWorksheet is a string. The worksheet to be deleted is in another workbook
> and for this particular workbook, the worksheet does not exist. (For other
> workbooks, it does exist) and the workbook is not protected.
>
> Is there a "test" I need to run to check to see if the worksheet exists
> before I delete?
>
> Again, thanks for any assistance you can give me.
>
> Thx
> MSweetG222
>
> "Chip Pearson" wrote:
>
> > You usually receive an "Object Disconnected" error when you attempt to use a
> > variable that refers to an object that has been deleted. See
> > http://www.cpearson.com/excel/ConnectedObject.htm for more information about
> > disconnected variables.
> >
> > For example, you can get a disconnect error with
> >
> > Dim WS As Worksheet
> > Set WS = Worksheets(2)
> > Application.DisplayAlerts = False
> > Worksheets(2).Delete
> > Application.DisplayAlerts = True
> > Debug.Print WS.Name
> >
> > Here, WS no longer refers to an existing worksheet (it got deleted) so
> > you'll a disconnect error (WS does not automatically get set to Nothing)..
> >
> > But this doesn't seem to make sense in the code you posted. Is sWorksheet a
> > String variable? Does the sheet named in the sWorksheet variable exist in
> > the ActiveWorkbook (which may not be the same as the workbook containing the
> > code)? Is the workbook protected?
> >
> >
> > --
> > Cordially,
> > Chip Pearson
> > Microsoft MVP - Excel
> > Pearson Software Consulting, LLC
> > www.cpearson.com
> > (email on the web site)
> >
> >
> >
> > "MSweetG222" <(E-Mail Removed)> wrote in message
> > news:8C8B19FC-7A0D-4796-BECF-(E-Mail Removed)...
> > > Chip - here is the error ... -2147417848 Automation error (I cut and
> > > pasted
> > > from the immediate window, ie: err.number & err.description)
> > >
> > > Here is what I receive when I run your procedure...
> > > "The object invoked has disconnected from its clients. "
> > >
> > > The line of code that it was received on ...
> > > Sheets(sWorksheet).Delete
> > > where sWorksheet is a sheet name
> > >
> > > Is that information helpful?
> > >
> > > Thx
> > > MSweetG222
> > >
> > >
> > >
> > > "Chip Pearson" wrote:
> > >
> > >> Are you sure that you got the error message number right? The value you
> > >> provide causes an overflow on a Long data type, and system error messages
> > >> are always Long data types.
> > >>
> > >> You can normally retrieve the exact error text associated with a system
> > >> error number using the GetSystemErrorMessageText function described on
> > >> http://www.cpearson.com/excel/FormatMessage.htm
> > >>
> > >> This procedure, however, requires a Long data type for the error number,
> > >> and
> > >> your error number is not a Long.
> > >>
> > >> All that said, it sounds to me like you have the structure of the
> > >> workbook
> > >> protected. Go to the Tools menu, choose Protection, and select UnProtect
> > >> Workbook. Supply the appropriate password if prompted.
> > >>
> > >>
> > >> --
> > >> Cordially,
> > >> Chip Pearson
> > >> Microsoft MVP - Excel
> > >> Pearson Software Consulting, LLC
> > >> www.cpearson.com
> > >> (email on the web site)
> > >>
> > >>
> > >> "MSweetG222" <(E-Mail Removed)> wrote in message
> > >> newsF4175AF-2C8A-4118-BD4F-(E-Mail Removed)...
> > >> >I received a -21474147848 error code (descr: method of 'Delete' of
> > >> >object
> > >> > '_Worksheet' failed) when deleting a worksheet (using vba). The vba
> > >> > code
> > >> > is
> > >> > held in a .xla file. This error issue was only occurring when I used a
> > >> > particular workbook. I have no issues performing the same actions in
> > >> > a
> > >> > different .xls workbook.
> > >> >
> > >> > I don't know if I solved the issue or just delayed it, but this is what
> > >> > I
> > >> > did...
> > >> >
> > >> > I modified the .xla code to 1. set the workbook calculation status to
> > >> > Manual, 2. performed the delete worksheet code and then 3. returned the
> > >> > workbook calcuation to Automatic.
> > >> >
> > >> > Comments?
> > >> >
> > >> > Thx
> > >> > MSweetG222
> > >> >
> > >>
> > >>
> > >>

> >
> >
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?TVN3ZWV0RzIyMg==?=
Guest
Posts: n/a
 
      20th Nov 2006
Thank you Chip & Dave for your help!!

MSweetG222



"MSweetG222" wrote:

> I received a -21474147848 error code (descr: method of 'Delete' of object
> '_Worksheet' failed) when deleting a worksheet (using vba). The vba code is
> held in a .xla file. This error issue was only occurring when I used a
> particular workbook. I have no issues performing the same actions in a
> different .xls workbook.
>
> I don't know if I solved the issue or just delayed it, but this is what I
> did...
>
> I modified the .xla code to 1. set the workbook calculation status to
> Manual, 2. performed the delete worksheet code and then 3. returned the
> workbook calcuation to Automatic.
>
> Comments?
>
> Thx
> MSweetG222
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Code from a Worksheet is Locking Up Keith Microsoft Excel Programming 5 8th Sep 2009 08:53 PM
error: 2147417848 aundrea Microsoft Excel New Users 1 22nd Sep 2008 08:50 PM
Run-Time error '-2147417848 (80010108)': Automation error The object invoked has disconnected from its clients SeangSTM Microsoft Excel Programming 0 28th Apr 2006 07:46 PM
Run-Time error '-2147417848 (80010108)': Automation error The object invoked has disconnected from its clients SeangSTM Microsoft Excel Programming 0 28th Apr 2006 07:45 PM
deleting worksheet code in generated workbooks Winshent Microsoft Excel Programming 1 29th Sep 2004 05:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.