I would like to know ... How can we put data into an Excel spreadsheet from a form.
If I have Name & Proffession fields in my form and I want these to be stored in different cells of an Excel sheets...How can I do it .. ?
Printable View
I would like to know ... How can we put data into an Excel spreadsheet from a form.
If I have Name & Proffession fields in my form and I want these to be stored in different cells of an Excel sheets...How can I do it .. ?
you can do that using ado and sql statement (insert statement)
refer to this thread also
http://vbforums.com/showthread.php?t=394651
Should do it.Quote:
First you have to reference the Excel library in Projects/Reference Menu in VB6.
Then you create a ExcelApp Object and a Worksheet object.
The Worksheet Object has a Cells or a Range object that you can manipulate.
Try the following code:
Dim objExcel as Excel.Application
Set objExcel = New Excel.Application
objExcel.Visible = True
objExcel.SheetsInNewWorkbook = 1
objExcel.Workbooks.Add
With objExcel.ActiveSheet
.Range("A1").value = "Heading 1"
.Range("B1").value = "Data 1"
etc, etc,etc....
End With
Silvy ... I am sorry ... can you give me sample code...
You still need to add a reference to the Excel library in projects-> references menu
VB Code:
' Create our new objects ' Global Declarations Dim objExcel as Excel.Application dim RowCount as integer sub Form_Load() Set objExcel = New Excel.Application objExcel.Visible = True objExcel.SheetsInNewWorkbook = 1 objExcel.Workbooks.Add 'This refers to our active sheet With objExcel.ActiveSheet .Range("A1").value = "Name" .Range("B1").value = "Profession" RowCount = 1 End With end sub sub SaveText(byval strName as string, byval strProf as string) RowCount = RowCount + 1 with objexcel.activesheet .range("A" & rowcount).value = strName .range("B" & RowCount).value = strProf end with end sub 'To add stuff, say from a commandbutton: Sub Command1_Click() SaveText(txtName.text, txtProf.text) txtName.text = "" txtProf.text = "" end sub
Does that help?
one good way is to export all the contents of a flex grid to an excel sheet.
refer si_the_geek's manual on excel .u will find all that u need .also rhinobull has some excellent code on this topic!!
good luck
If you're still using the code i posted, i found it was always handy to record a macro in VBA (i.e. in excel), doing what i wanted to do, then recoding that macro in vb
just a suggestion
I fully agree with that - part of my tutorial explains how to convert the macro to code in your VB program.
Link below ;)Quote:
Originally Posted by litlewiki
If you have Excel installed check out my Tutorial:
http://www.vbforums.com/showthread.p...ighlight=Excel
If you don't have Excel installed check out this ADO method:
http://www.vbforums.com/showthread.p...ighlight=Excel