Getting numbers out of Excel via VB6

Thread Solved

Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Getting numbers out of Excel via VB6

 
0
  #1
Oct 2nd, 2007
I'm currently making a program that gives the person who uses it information about the costs for a shipment.

The transport company changes it numbers quite often, so in Excel the numbers are easier to change. I want to have, let's say, C3 be displayed every time in VB in the listbox, Holland, 500kg and a Postcal code is selected.

Does anyone know how I can achieve this?

Thanks in advance,

Q~

Edit:
Here is a piece of code how it is right now:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If lstCountry = "Belgium" And lstWeight = "till 50kg" And lstPostal = "66-69" Then
  2. lstPrice.AddItem ("€ 47,00")
  3. lstTime.AddItem ("48 hours")
  4. End If
I would like it to be something like this:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If lstCountry = "Belgium" And lstWeight = "till 50kg" And lstPostal = "66-69" Then
  2. lstPrice.AddItem ("Sheet.Belg(C3)")
  3. lstTime.AddItem ("Sheet.Belg(C16)")
  4. End If
Last edited by Qpido; Oct 2nd, 2007 at 9:08 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: Getting numbers out of Excel via VB6

 
0
  #2
Oct 2nd, 2007
Hi,

Check this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim xl As Object
  2. Dim xlsheet As Object
  3. Dim xlwbook As Object
  4.  
  5. Set xl = CreateObject("Excel.Application")
  6. Set xlwbook = xl.Workbooks.Open("c:\temp.xls", , True)
  7. Set xlsheet = xlwbook.Sheets.Item(1)
  8.  
  9. Me.List1.additem (xlsheet.range("A17"))
  10.  
  11. xl.ActiveWorkbook.Close False, "c:\temp.xls"
  12. xl.Quit
  13. Set xl = Nothing
  14. Set xlwbook = Nothing
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Re: Getting numbers out of Excel via VB6

 
0
  #3
Oct 3rd, 2007
Thanks for the tip.

I got the information filling in the listboxes, can you explain to me what the "Me." is useful for?
Also I get an error message:

"The instruction at "0x30a666d5" referenced memory at "0x0065008e". The memory could not be "read".

Click on OK to terminate the program
Click on CANCEL to debug the program"

Excel is still open in Task Manager though.

Thanks again,

Q~
Last edited by Qpido; Oct 3rd, 2007 at 9:06 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 147
Reputation: hopalongcassidy is an unknown quantity at this point 
Solved Threads: 13
hopalongcassidy's Avatar
hopalongcassidy hopalongcassidy is offline Offline
Junior Poster

Re: Getting numbers out of Excel via VB6

 
0
  #4
Oct 3rd, 2007
Dear qpido,

From your question, it is not clear what you are looking for. VB is supported in both Excel and in MS Access, although the have different object models. So, are you trying to get data from an en Excel spreadsheet into a listbox in a MS Access Form or vice versa?

By the way, "Me." is like "this->" in C++ or "this." in Java.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: Getting numbers out of Excel via VB6

 
0
  #5
Oct 3rd, 2007
Hi,

I don't know what is generating the error as I tested my code and it worked correctly. Try to debug in order to find where the error is. A for Me. you can remove it where the "Me" word references the form you are currently using and am used for using it.
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Re: Getting numbers out of Excel via VB6

 
0
  #6
Oct 4th, 2007
I tried putting the code into a new project, where everything is new, but I still got the exact same error.

Just to be clear, I'm trying to take data out of cell H5 in Sheet "Belg" from Bosman2.xls,
then I want it to be printed in lstPrijs.

Could it be that I need to add something to Excel's references?

I read that on some places, but as I'm very new to programming, could someone explain me exactly how one goes about doing this.

Thanks so much,

Q~
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Re: Getting numbers out of Excel via VB6

 
0
  #7
Oct 5th, 2007
Here is an example of my code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub BelgPo ()
  2.  
  3. Dim xl As Object
  4. Dim xlsheet As Object
  5. Dim xlwbook As Object
  6.  
  7. Set xl = CreateObject("Excel.Application")
  8. Set xlwbook = xl.Workbooks.Open("c:\Verzend\Bosman2.xls", , True)
  9. Set xlsheet = xlwbook.Sheets.Item("Belg")
  10.  
  11. If lstLanden = "België" And lstGewicht = "t/m 50kg" And lstPostcode = "10-39" Or lstLanden = "België" And lstGewicht = "t/m 50kg" And lstPostcode = "90-99" Then
  12. Me.lstPrijs.AddItem (sheet.range("h5"))
  13. lstTijdsduur.AddItem ("24 uur")
  14. End If
  15.  
  16. xl.ActiveWorkbook.Close False, "c:\Verzend\Bosman2.xls"
  17. xl.Quit
  18. Set xl = Nothing
  19. Set xlwbook = Nothing
  20.  
  21. End Sub

I hope I've said enough.

Q~
Last edited by Qpido; Oct 5th, 2007 at 5:59 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 30
Reputation: yello is an unknown quantity at this point 
Solved Threads: 4
yello yello is offline Offline
Light Poster

Re: Getting numbers out of Excel via VB6

 
0
  #8
Oct 7th, 2007
Me.lstPrijs.AddItem (sheet.range("h5"))
Change this to
Me.lstPrijs.AddItem (xlSheet.range("h5").Value)
www.easyprograming.com
Make Your Programing Easy
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Re: Getting numbers out of Excel via VB6

 
0
  #9
Oct 9th, 2007
I've tried changing it to that, but now it just takes like 3 seconds to load the cell and then I get the same error message as first.

When I try to debug it says there is a problem with Excel and it will be terminated.

Maybe the problem is with Excel?

Any thoughts on this?

Q~
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 12
Reputation: Qpido is an unknown quantity at this point 
Solved Threads: 0
Qpido Qpido is offline Offline
Newbie Poster

Re: Getting numbers out of Excel via VB6

 
0
  #10
Oct 9th, 2007
Also a new problem has come up,

Take a look at this code :

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim xl As Object
  2. Dim xlsheet As Object
  3. Dim xlwbook As Object
  4.  
  5. Set xl = CreateObject("Excel.Application")
  6. Set xlwbook = xl.Workbooks.Open("c:\Verzend\Bosman2.xls", , True)
  7. Set xlsheet = xlwbook.Sheets.Item("Belg")
  8.  
  9. If lstGewicht = "t/m 50kg" And lstPostcode = "10-39" Or lstGewicht = "t/m 50kg" And lstPostcode = "90-99" Then
  10. Me.lstPrijs.AddItem (xlsheet.range("h5").Value)
  11. End If
  12.  
  13. xl.ActiveWorkbook.Close False, "c:\Verzend\Bosman2.xls"
  14. xl.Quit
  15. Set xl = Nothing
  16. Set xlwbook = Nothing

Ok, when I've clicked the 50kg and the 10-39, it shows the correct amount in the Price List, ofcourse with the error. But then if I click 90-99, it shows all the numbers from the H section in excel, where he's supposed to bring up the same number as the 10-39.

I'm getting so frustrated !

Q~
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC