This is the code for creating an excel workbook and excel worksheets and how to write anything in the sheet :
First, Excel object library must be refernced, then write this code :
CODE
Dim objExcel as Excel.Application
Set objExcel = New Excel.Application
objExcel.Visible = True
ObjExcel.SheetsInNewWorkbook = 1
ObjExcel.Workbooks.Add
This is the code for crearting an excel workbook and excel worksheets . In this part we create an excel workbook. we set how many worksheets we want in the workbook in the forth line.
The following code is for writing in the active worksheet :
CODE
with objExcel.ActiveSheet
.Cells(1, 2).Value = "10"
.Cells(2, 2).Value = "20"
.Cells(3, 2).Value = "SUM(B1:B2)"
.Range("A3")= "Total"
End With
In this part we write in the active worksheet what we want. We refer to the cell with two methods :
1. The first method by writing :
CODE
objExcel.ActiveSheet.Cells(1, 2).Value = The Text or the Formula we want , like that in Line4 in the previous example, we want to write
That is like the code in the previous example. We refer to the cell by writing the syntax like that :
CODE
objExcel.ActiveSheet.Cells([b][i]The number of the Row[/i][/b],[b][i] The number of the Column[/i][/b]).Value = The Text we want to write
2. The second by writing :
CODE
objExcel.ActiveSheet.Range("A3") = The Text we want to write
This is like the code in the previous example. we refer to the cell by writing the syntax like that :
CODE
objExcel.ActiveSheet.Range([b][i]The Name of the Cell in the Excel WorkSheet[/i][/b]) = The Text we want to write
But I don't know if whether we can write a Formula in the Cell by this syntax or not.