p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 15th, 2004, 09:49 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: PERIGUEUX, , France.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old December 16th, 2004, 01:48 AM
Friend of Wrox
Points: 616, Level: 9
Points: 616, Level: 9 Points: 616, Level: 9 Points: 616, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old December 16th, 2004, 05:18 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: PERIGUEUX, , France.
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



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old December 16th, 2004, 05:58 AM
Friend of Wrox
Points: 616, Level: 9
Points: 616, Level: 9 Points: 616, Level: 9 Points: 616, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old December 16th, 2004, 06:36 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: PERIGUEUX, , France.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old December 16th, 2004, 07:27 AM
Friend of Wrox
Points: 616, Level: 9
Points: 616, Level: 9 Points: 616, Level: 9 Points: 616, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 07: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 05: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 04:30 AM



All times are GMT -4. The time now is 07:15 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc