note that you have to referance Microsoft.Office.Interop.Excel assembly:
project>>add reference>> check Microsoft Excel x.xx Object Libary
Imports Microsoft.Office.Interop
Public Class Form1
Private exapp As Excel.Application
Private xlwb As Excel.Workbook
Private xlws As Excel.Worksheet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
exapp = New Excel.Application
xlwb = exapp.Workbooks.Add()
xlws = xlwb.Worksheets.Add()
xlws.Name = "MY WS"
xlws.Move(After:=xlwb.Sheets(xlwb.Sheets.Count))
' note: .value is a Range property
xlws.Cells(1, 2) = "standard"
xlwb.Application.DisplayAlerts = False
exapp.Visible = True
xlwb.Worksheets("sheet1").Delete()
xlwb.SaveAs("C:\Users\john\Desktop\test.xlsx")
xlwb.Close()
End Sub
End Class
as for your update:
even that Excel.Worksheet and Excel.Workbook are not static objects, in your case you dont need the make an instant of the (using new) because you are initializing them with new workbook and new worksheet.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim excelRange As Excel.Range
Dim excelApp As Excel.Application
Dim excelWB As Excel.Workbook
Dim excelWS As Excel.Worksheets
' excelWB = New Workbook - you dont need an instant
' If madeSheet = False Then
excelApp = New Excel.Application
excelWB = excelApp.Workbooks.Add
excelApp.Visible = True
' End If
' excelWS = New Worksheet - you dont need an instant
End Sub
8
solved vb.net late bindings issue even after setting the variable