Try to delete a worksheet in Excel

  • Thread starter Thread starter Rene
  • Start date Start date
R

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
 
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
 
Let's see your entire code.


Rene said:
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
 
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
 
Back
Top