Results 1 to 9 of 9

Thread: Using the OLE and Excel, how do i get info from excel??

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wisconsin
    Posts
    33

    Using the OLE and Excel, how do i get info from excel??

    I have an excel file on my form and i have it all set up to make this total up with the part prices and quantities that i enter, it even gives me a grand total. I want to get that total out into a separate text box, how would i do that, could u set it up for me so that i could put it into the commands for a cmd button. that would be very helpful thanks

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Load data from Excel back into VB:
    VB Code:
    1. Private Sub cmdUpdate_Click()
    2. Dim lRow As Long, lCol As Long, dValue As Double, dYear As Integer, dID As String
    3. Dim obExcelApp As Excel.Application
    4. Dim obWorkBook As Excel.Workbook
    5. Dim c As Excel.Range
    6.     Set obExcelApp = CreateObject("Excel.Application")
    7.     Set obWorkBook = obExcelApp.Workbooks.Open("C:\temp\temp.xls")
    8.     For Each c In Excel.ActiveSheet.UsedRange
    9.         dValue = c.Value
    10.         MsgBox dValue ' Just show the data
    11.     Next c    
    12.     Set obWorkBook = Nothing
    13.     Set obExcelApp = Nothing
    14. End Sub
    You might not want ALL the data from Excel, so you can cut down the FOR EACH line to something smaller.
    MsgBox Excel.ActiveSheet.Range("A6")

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wisconsin
    Posts
    33
    that second line with the "Dim obExcelApp As Excel.Application" pops up an error message "Compile Error, User-Defined Type not defined"
    what is that supposed to mean?? Thanks for ur help

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    That means you need a reference to Excel.

    Project menu - References.
    Add Microsoft Excel

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wisconsin
    Posts
    33

    yea.. but...

    hey now i want to get the info out but that isnt really working, this is waht i have for a code now

    Dim lRow As Long, lCol As Long, dValue As Double, dYear As Integer, dID As String
    Dim obExcelApp As Excel.Application
    Dim obWorkBook As Excel.Workbook
    Dim c As Excel.Range
    Set obExcelApp = CreateObject("Excel.Application")
    Set obWorkBook = obExcelApp.Workbooks.Open("C:\work orders\partsused.xls")
    txtmaterals.Text = Excel.ActiveCell.Cells = (E12)
    Set obWorkBook = Nothing
    Set obExcelApp = Nothing


    OK then it gives me an error message RUNTIME ERROR 424, OBJECT REQUIRED. it was on this line:
    txtmaterals.Text = Excel.ActiveCell.Cells = (E12)

    so maybe thats the wrong way to get the info out, right?
    Well anyways im sure u know cuz its stumped my for over an hour today so Id really like ur help
    thanks

  6. #6
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Change
    txtmaterals.Text = Excel.ActiveCell.Cells = (E12)

    to:
    txtmaterals.Text = obExcelApp.ActiveCell.Cells = (E12)


    Or one of the other Objects if that one isn't correct!

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wisconsin
    Posts
    33
    no that one doesnt work

    i'll keep working on it
    thanks

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    Wisconsin
    Posts
    33
    OK I give up on trying to figure it out myself, ive spent 4 hrs.
    So what other options do i have to put in for the other objects??
    thanks a whole lot!

  9. #9
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    hi,

    txtmaterials.text=obWorkbook.range("E12").value

    this will solve u r problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width