|
|
 |
| Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning VB 6 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

December 15th, 2004, 09:49 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Location: PERIGUEUX, , France.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Writing Data to Excel from VB6
I'm lost using VB6 - not at all used to it and having trouble finding a simple way to open spreadshhet and write data to it.
No doubt simple, but I've only managed to access data in an existing sheet.
Preferably, I'd like a pointer to an example that creates a new excel file and worksheet, enters the data using SQL INSERT (is this not possible?) and saves the worksheet, all under programme control.
Thanks in advance...
Ru
|

December 16th, 2004, 01:48 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ru,
Just create a new form and paste the below by double clicking on it. I guess this code snippet would help you!
**************Code snippet starts here**************
Rem General Declaration
Dim objExcel As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet
Private Sub Form_Load()
Rem Initialization of variables
Set objExcel = New Excel.Application
Set objWorkBook = objExcel.Workbooks.Add
Set objWorkSheet = objWorkBook.Worksheets("Sheet1")
Set objWorkSheet = objExcel.ActiveSheet
objWorkSheet.Range("A1").Value = "Vadivel"
objExcel.Visible = True ' The created excel workbook would be visible.
objWorkBook.Close (True) 'This will fire the SaveAs dialog box
End Sub
**************Code snippet ends here**************
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|

December 16th, 2004, 05:18 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Location: PERIGUEUX, , France.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, for the code Vadivel.
Can you help me once more?
I get the error
Compile error:
User defined type not defined
I assume I am not declaring or linking to 'something' that permits me to manipulate an excel spreadsheet directly from VB6, but I don't know how or where to do this...
thanks again,
Ru
|

December 16th, 2004, 05:58 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ru,
I guess you didn't add reference to the Excel object library.
(Program >> Reference >> Microsoft Excel 9.0 Object Library)
Just add it, the code should work.
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|

December 16th, 2004, 06:36 AM
|
|
Registered User
|
|
Join Date: Dec 2004
Location: PERIGUEUX, , France.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Vadivel, you're a star!
Thanks for the tips - I think I'm all set now - the rest (I hope) I can figure out as I go along...
I read on your website that your dad was ill, but is back on his feet now. 'Go mairfhidh se an chead' - an Irish blessing meaning 'may he live to be 100'
All the best for you and yours over the holiday period...
Ru
|

December 16th, 2004, 07:27 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ru,
Thanks for wishing my father for long life & thanx for your compliments as well.
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |