Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting a worksheet - impossible!

Hello,

I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!

Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?

Many many thanks for your help
Luvic.

static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =
ExcelApp.Workbooks.Open(path,0,true,5,"","",true,X lPlatform.xlWindows,"",false,false,0,false,null,nu ll);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}

private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch { }
finally
{
o = null;
}
}

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Deleting a worksheet - impossible!

Couldn't tell you about non-VB code but;
Are you using "workbook" as the name of a variable of type Workbook ?
Not sure if matters for you, but may not a good idea to use a word from the
object model, WB would be better.

((Worksheet)workbook.Sheets["Sheet1"]).Delete();
would be
WB.Sheets("Sheet1").Delete
assuming it is not the last sheet in the WB.

NikcHK

wrote in message
ups.com...
Hello,

I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!

Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?

Many many thanks for your help
Luvic.

static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =

ExcelApp.Workbooks.Open(path,0,true,5,"","",true,X lPlatform.xlWindows,"",fal
se,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}

private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch { }
finally
{
o = null;
}
}



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting a worksheet - impossible!


Thanks Nick.

I don't think that is the issue.

The code is written in C# which is a case sensitive language.
Therefore the word "workbook" is safe to use, and does not conflict
with the class "Workbook".
If there was an error there, it would be picked up at design time by
the compiler.
It's got to be something else!

Ps. I am able to edit the data in the spreadsheet and save it, so I
don't think it is a permissions problem.

Luvic.


NickHK wrote:

Couldn't tell you about non-VB code but;
Are you using "workbook" as the name of a variable of type Workbook ?
Not sure if matters for you, but may not a good idea to use a word from the
object model, WB would be better.

((Worksheet)workbook.Sheets["Sheet1"]).Delete();
would be
WB.Sheets("Sheet1").Delete
assuming it is not the last sheet in the WB.

NikcHK

wrote in message
ups.com...
Hello,

I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!

Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?

Many many thanks for your help
Luvic.

static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =

ExcelApp.Workbooks.Open(path,0,true,5,"","",true,X lPlatform.xlWindows,"",fal
se,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}

private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch { }
finally
{
o = null;
}
}


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Deleting a worksheet - impossible!

Which error are you getting ?

NickHK

wrote in message
oups.com...

Thanks Nick.

I don't think that is the issue.

The code is written in C# which is a case sensitive language.
Therefore the word "workbook" is safe to use, and does not conflict
with the class "Workbook".
If there was an error there, it would be picked up at design time by
the compiler.
It's got to be something else!

Ps. I am able to edit the data in the spreadsheet and save it, so I
don't think it is a permissions problem.

Luvic.


NickHK wrote:

Couldn't tell you about non-VB code but;
Are you using "workbook" as the name of a variable of type Workbook ?
Not sure if matters for you, but may not a good idea to use a word from

the
object model, WB would be better.

((Worksheet)workbook.Sheets["Sheet1"]).Delete();
would be
WB.Sheets("Sheet1").Delete
assuming it is not the last sheet in the WB.

NikcHK

wrote in message
ups.com...
Hello,

I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!

Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?

Many many thanks for your help
Luvic.

static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =


ExcelApp.Workbooks.Open(path,0,true,5,"","",true,X lPlatform.xlWindows,"",fal
se,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}

private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch { }
finally
{
o = null;
}
}




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting a worksheet - impossible!


I've modified the code to use "Application" instead of
"ApplicationClass" and that seems to be working.
halelujah!

Thanks for the help Nick.

Regards,
Luvic


NickHK wrote:

Which error are you getting ?

NickHK

wrote in message
oups.com...

Thanks Nick.

I don't think that is the issue.

The code is written in C# which is a case sensitive language.
Therefore the word "workbook" is safe to use, and does not conflict
with the class "Workbook".
If there was an error there, it would be picked up at design time by
the compiler.
It's got to be something else!

Ps. I am able to edit the data in the spreadsheet and save it, so I
don't think it is a permissions problem.

Luvic.


NickHK wrote:

Couldn't tell you about non-VB code but;
Are you using "workbook" as the name of a variable of type Workbook ?
Not sure if matters for you, but may not a good idea to use a word from

the
object model, WB would be better.

((Worksheet)workbook.Sheets["Sheet1"]).Delete();
would be
WB.Sheets("Sheet1").Delete
assuming it is not the last sheet in the WB.

NikcHK

wrote in message
ups.com...
Hello,

I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!

Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?

Many many thanks for your help
Luvic.

static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =


ExcelApp.Workbooks.Open(path,0,true,5,"","",true,X lPlatform.xlWindows,"",fal
se,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}

private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComO bject(o);
}
catch { }
finally
{
o = null;
}
}



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 of worksheet oldLearner57 Excel Discussion (Misc queries) 1 August 28th 08 06:31 AM
Deleting a worksheet but retaining values from the worksheet. [email protected] Excel Discussion (Misc queries) 1 September 13th 06 03:00 PM
Deleting a worksheet but retaining values from the worksheet. [email protected] Excel Discussion (Misc queries) 1 September 13th 06 02:48 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
deleting worksheet Laurent M Excel Discussion (Misc queries) 1 January 25th 05 11:31 AM


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