Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > VB6 and Excel2000


Reply
 
Thread Tools Display Modes
  #1  
Old 11-23-2001, 01:39 PM
Asapkota
Guest
 
Posts: n/a
Question VB6 and Excel2000


Hello all

I need to write a Vb program that takes data from a user form and updates an existing spreadsheet's certain cells with the new data when a command button is pressed. After that it needs to print the spreadsheet. How do I do this. I already made the interface. I need to know how to open an excel spreadsheet and update cells in the spreadsheet from VB and finally print the spreadsheet. Any help is greatly appreciated.
Reply With Quote
  #2  
Old 11-23-2001, 01:49 PM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default Re: VB6 and Excel2000

__________________
Posting Guidelines
Reply With Quote
  #3  
Old 11-24-2001, 09:49 PM
Asapkota
Guest
 
Posts: n/a
Default Re: VB6 and Excel2000

I used the following code from the post you gave me

----
Option Explicit

Private Sub Command1_Click()

Dim Index As Integer
Index = 1
Dim obExcelApp As Excel.Application
Dim obWorkBook As Excel.Workbook
Set obExcelApp = CreateObject("Excel.Application")
Set obWorkBook = obExcelApp.Workbooks.Open("c:\tomtest.xls")
obWorkBook.Worksheets(Index).Range("a1") = "thank you"
obWorkBook.Worksheets(Index).Range("b4") = "Very much"
obExcelApp.Visible = True
Set obWorkBook = Nothing
Set obExcelApp = Nothing

End Sub
----

I receive the following error when I run the program

Compile Error:

"User-defined type not defined"

It points to the following code

"Dim obExcelApp As Excel.Application"

What did I forget to do?
Reply With Quote
  #4  
Old 11-24-2001, 10:50 PM
Asapkota
Guest
 
Posts: n/a
Question Re: VB6 and Excel2000

I finally got the above code to work. I changed
Dim obExcelApp As Excel.Application
Dim obWorkBook As Excel.Workbook
to
Dim obExcelApp As Object
Dim obWorkBook As Object
and it worked fine.

Now, I have one question

Set obWorkBook = obExcelApp.Workbooks.Open("c:\tomtest.xls")

Why do I have to enter the full path of the excel spreadsheet I want to open. How do I make it open the spreadsheet with just the spreadsheet name. Look for it on the directory where the program is being run from.
Reply With Quote
  #5  
Old 11-25-2001, 09:35 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default Re: VB6 and Excel2000

You should get rid of the Object and put it back the way it was, then go to
the References dialog from the Projects menu, find the Excel Object Library
check it and OK. This will give you early binding, which is much more
efficient than the late binding you have changed to.

The path can be relative to your app's directory. Just to be on the safe
side, you might want to use App.Path & "\" & "mysheet.xls"
__________________
Posting Guidelines
Reply With Quote
  #6  
Old 11-25-2001, 03:27 PM
Asapkota
Guest
 
Posts: n/a
Default Re: VB6 and Excel2000

Thanks a lot for the help. Everything works fine. How do I print the excel spreadsheet after updating it with new data
Reply With Quote
  #7  
Old 11-25-2001, 04:58 PM
Timbo's Avatar
Timbo Timbo is offline
Green-Eyed

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Bangkok, Thailand
Posts: 10,261
Default Re: VB6 and Excel2000

obWorkBook.ActiveSheet.PrintOut
__________________
"He's not the Messiah. He's a very naughty boy!" - Brian's mum

Can't find the answer? >> Try something new!
Become a Professional
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->