Home All Groups Group Topic Archive Search About

Try to delete a worksheet in Excel

Author
8 Sep 2006 6:45 PM
Rene
Hi Proggies,

i try to delete an excel worksheet but nothing happens (work on vb.net 2005)

.....
xlSheet = xlApp.Sheets("Master")
xlSheet.select
xlSheet.delete

also try

objWkb.Worksheets(sWksName).Delete

Where is the mistake ?

thx and nice weekend

Rene

Author
8 Sep 2006 10:32 PM
Scott M.
And what was your VB.NET question?


Show quoteHide quote
"Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
news:Ogdjwb30GHA.480@TK2MSFTNGP06.phx.gbl...
> Hi Proggies,
>
> i try to delete an excel worksheet but nothing happens (work on vb.net
> 2005)
>
> ....
> xlSheet = xlApp.Sheets("Master")
> xlSheet.select
> xlSheet.delete
>
> also try
>
> objWkb.Worksheets(sWksName).Delete
>
> Where is the mistake ?
>
> thx and nice weekend
>
> Rene
>
>
Author
9 Sep 2006 8:11 AM
Rene
If you use excel vba, the code will be work.
If you using vb.net to build an Excel File you can´t delete a worksheet in
Excel with this typ of code.
vb.Net runs over the delete statement an nothing happens.

Sorry if my question is incomprehensibly

Rene

Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> schrieb im Newsbeitrag
news:ORuLsa50GHA.5048@TK2MSFTNGP05.phx.gbl...
> And what was your VB.NET question?
>
>
> "Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
> news:Ogdjwb30GHA.480@TK2MSFTNGP06.phx.gbl...
>> Hi Proggies,
>>
>> i try to delete an excel worksheet but nothing happens (work on vb.net
>> 2005)
>>
>> ....
>> xlSheet = xlApp.Sheets("Master")
>> xlSheet.select
>> xlSheet.delete
>>
>> also try
>>
>> objWkb.Worksheets(sWksName).Delete
>>
>> Where is the mistake ?
>>
>> thx and nice weekend
>>
>> Rene
>>
>>
>
>
Author
9 Sep 2006 2:21 PM
Scott M.
Let's see your entire code.


Show quoteHide quote
"Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
news:uJDShe%230GHA.1252@TK2MSFTNGP04.phx.gbl...
> If you use excel vba, the code will be work.
> If you using vb.net to build an Excel File you can´t delete a worksheet in
> Excel with this typ of code.
> vb.Net runs over the delete statement an nothing happens.
>
> Sorry if my question is incomprehensibly
>
> Rene
>
> "Scott M." <s-mar@nospam.nospam> schrieb im Newsbeitrag
> news:ORuLsa50GHA.5048@TK2MSFTNGP05.phx.gbl...
>> And what was your VB.NET question?
>>
>>
>> "Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
>> news:Ogdjwb30GHA.480@TK2MSFTNGP06.phx.gbl...
>>> Hi Proggies,
>>>
>>> i try to delete an excel worksheet but nothing happens (work on vb.net
>>> 2005)
>>>
>>> ....
>>> xlSheet = xlApp.Sheets("Master")
>>> xlSheet.select
>>> xlSheet.delete
>>>
>>> also try
>>>
>>> objWkb.Worksheets(sWksName).Delete
>>>
>>> Where is the mistake ?
>>>
>>> thx and nice weekend
>>>
>>> Rene
>>>
>>>
>>
>>
>
>
Author
11 Sep 2006 8:26 AM
Rene
Hello Scott,
here is my code:

        Dim Vorlagenverzeichnis As String = "...."
        Dim aktWorkbook As String
        Dim xlApp As New Excel.Application
        Dim xlSheet As Excel.Worksheet
        xlApp.Workbooks.Add(Template:=Vorlagenverzeichnis)
        aktWorkbook = xlApp.ActiveWorkbook.Name
        xlApp.Workbooks(aktWorkbook).Sheets("Master").Copy(After:=xlApp.Sheets(xlApp.ActiveWorkbook.Sheets.Count))
        xlApp.ActiveSheet.Name = "New Create"

        xlSheet = xlApp.Workbooks(aktWorkbook).ActiveSheet
        xlSheet.Delete()
        xlApp.Application.Visible = True

This does not work, i add a reference to Excel 10 Com Object (vb.net 1.0 and
2.0)

I try a little bit last weekend and this one will work
May late binding is a better one to use

        Dim Excel As Object
        Excel = CreateObject("Excel.application")
        With Excel
            .SheetsInNewWorkbook = 4
            .Workbooks.Add()
            .Worksheets(1).Select()
            .worksheets(1).Name = "Test"
            .worksheets("Test").delete()
            .activeWorkbook.close()
        End With
        Excel.Quit()
        Excel = Nothing
        GC.Collect()

Regards Rene


Show quoteHide quote
"Scott M." <s-mar@nospam.nospam> schrieb im Newsbeitrag
news:%2332kusB1GHA.3372@TK2MSFTNGP04.phx.gbl...
> Let's see your entire code.
>
>
> "Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
> news:uJDShe%230GHA.1252@TK2MSFTNGP04.phx.gbl...
>> If you use excel vba, the code will be work.
>> If you using vb.net to build an Excel File you can´t delete a worksheet
>> in Excel with this typ of code.
>> vb.Net runs over the delete statement an nothing happens.
>>
>> Sorry if my question is incomprehensibly
>>
>> Rene
>>
>> "Scott M." <s-mar@nospam.nospam> schrieb im Newsbeitrag
>> news:ORuLsa50GHA.5048@TK2MSFTNGP05.phx.gbl...
>>> And what was your VB.NET question?
>>>
>>>
>>> "Rene" <rene.DELETESPAMspreckelsen@gmx.de> wrote in message
>>> news:Ogdjwb30GHA.480@TK2MSFTNGP06.phx.gbl...
>>>> Hi Proggies,
>>>>
>>>> i try to delete an excel worksheet but nothing happens (work on vb.net
>>>> 2005)
>>>>
>>>> ....
>>>> xlSheet = xlApp.Sheets("Master")
>>>> xlSheet.select
>>>> xlSheet.delete
>>>>
>>>> also try
>>>>
>>>> objWkb.Worksheets(sWksName).Delete
>>>>
>>>> Where is the mistake ?
>>>>
>>>> thx and nice weekend
>>>>
>>>> Rene
>>>>
>>>>
>>>
>>>
>>
>>
>
>