Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2004, 09:49 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wildergoose
Default 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
 
Old December 16th, 2004, 01:48 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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
 
Old December 16th, 2004, 05:18 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wildergoose
Default

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



 
Old December 16th, 2004, 05:58 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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
 
Old December 16th, 2004, 06:36 AM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to wildergoose
Default

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
 
Old December 16th, 2004, 07:27 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export the data from datagrid to excel in VB6 Sharad Singh Beginning VB 6 1 April 16th, 2007 06:00 AM
Reading and Writing data from Excel using VB? honey123 VB How-To 0 March 25th, 2006 08:48 AM
Writing to an Excel Worksheet in VB6 David Robinson Pro VB 6 1 August 27th, 2005 04:29 PM
Writing to a .BAT file using VB6 rhysduk VB How-To 17 January 7th, 2005 09:06 AM
Writing Data to excel acdsky VB How-To 3 June 3rd, 2004 03:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.