refering to this link Creating an Excel Application from VB.Net
I want to save my excel file to this path:
C:\Users\asdfme\Documents
with the filename format [PROJ_DATE].xls example:PROJ_20140703.xls
here is my code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Call temporaryValue()
Dim appXL As Excel.Application
Dim wbXl As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range
Dim strPathExcel As String
' Start Excel and get Application object.
appXL = CreateObject("Excel.Application")
appXL.Visible = True
' Add a new workbook.
wbXl = appXL.Workbooks.Add
shXL = wbXl.ActiveSheet
' Add table headers going cell by cell.
Dim heads() As String = {"", "MONo", "PostingDate", "DocDate", "SBU", "Operation", "Resource", "TimeType", "StartDate", "StartTime", "EndDate", "EndTime", "NoofResources", "Remarks", "Quantity", "Rejects"}
For head1 As Integer = 1 To 15
shXL.Cells(1, head1).Value = heads(head1)
Next
Dim body() As String = {"", txtmo.Text, PostingDate, DocDate, SBU, Operation, Session("user"), (ddltype.SelectedValue).ToUpper, lblsDate.Text, lblsTime.Text, lbleDate.Text, lbleTime.Text, no_ofres, lblrem.Text, txtgoods.Text, txtrejects.Text}
For body1 As Integer = 1 To 15
shXL.Cells(2, body1).Value = body(body1)
Next
appXL.Visible = True
appXL.UserControl = True
' Release object references.
wbXl.SaveAs(Filename:="C:\Users\asdfme\Documents\PROJ_20140703.xls")
raXL = Nothing
shXL = Nothing
wbXl = Nothing
appXL.Quit()
appXL = Nothing
Exit Sub
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
End Sub
when i run this code,
- it only create an excel file and ask me if i want to save the file.
- what i want is whenever i run this, the file will save with the file name format (written above) in the path i declare.
Please help. thank you
wbXl.SaveAs(Filename:="C:\Users\asdfme\Documents\PROJ_20140703.xls")excelsheets in your computer and change thefile location, i used to save the excel file towbXl.SaveAs(Filename:="C:\Documents and Settings\All Users\Desktop\PROJ_20140703.xls")