469,275 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Try to delete a worksheet in Excel

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
Sep 8 '06 #1
3 14976
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-***@nospam.nospamschrieb im Newsbeitrag
news:OR**************@TK2MSFTNGP05.phx.gbl...
And what was your VB.NET question?
"Rene" <re************************@gmx.dewrote in message
news:Og*************@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



Sep 9 '06 #2
Let's see your entire code.
"Rene" <re************************@gmx.dewrote in message
news:uJ****************@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-***@nospam.nospamschrieb im Newsbeitrag
news:OR**************@TK2MSFTNGP05.phx.gbl...
>And what was your VB.NET question?
"Rene" <re************************@gmx.dewrote in message
news:Og*************@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




Sep 9 '06 #3
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.C ount))
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
"Scott M." <s-***@nospam.nospamschrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP04.phx.gbl...
Let's see your entire code.
"Rene" <re************************@gmx.dewrote in message
news:uJ****************@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-***@nospam.nospamschrieb im Newsbeitrag
news:OR**************@TK2MSFTNGP05.phx.gbl...
>>And what was your VB.NET question?
"Rene" <re************************@gmx.dewrote in message
news:Og*************@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




Sep 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by mail2atulmehta | last post: by
1 post views Thread by GG | last post: by
5 posts views Thread by Shao Yong | last post: by
1 post views Thread by Rene | last post: by
3 posts views Thread by sun919 via DotNetMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.