|
-
Mar 27th, 2006, 01:33 AM
#1
Thread Starter
Lively Member
[RESOLVED] VB & Excel
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 .. ?
-
Mar 27th, 2006, 01:38 AM
#2
Frenzied Member
Re: VB & Excel
you can do that using ado and sql statement (insert statement)
refer to this thread also
http://vbforums.com/showthread.php?t=394651
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Mar 27th, 2006, 01:41 AM
#3
Conquistador
Re: VB & Excel
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
Should do it.
-
Mar 27th, 2006, 01:54 AM
#4
Thread Starter
Lively Member
Re: VB & Excel
Silvy ... I am sorry ... can you give me sample code...
-
Mar 27th, 2006, 02:15 AM
#5
Conquistador
Re: VB & Excel
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?
-
Mar 27th, 2006, 05:20 AM
#6
Re: VB & Excel
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
__________________
________________0îîî___
___îîî0________(___)____
__(___)_________) _/_____
___\_ (_________(_/______
____\_)_________________
-
Mar 27th, 2006, 05:42 AM
#7
Conquistador
Re: VB & Excel
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
-
Mar 27th, 2006, 10:00 AM
#8
Re: VB & Excel
I fully agree with that - part of my tutorial explains how to convert the macro to code in your VB program.
 Originally Posted by litlewiki
refer si_the_geek's manual on excel
Link below
-
Mar 28th, 2006, 08:38 AM
#9
Re: VB & Excel
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
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|