Results 1 to 4 of 4

Thread: using excel in vb 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    subdivision
    Posts
    7

    Unhappy using excel in vb 6

    hi! i wanted to know if it is possible to open an excel file in vb, access the cells and get its values. hope you can help me. i really, really need your help. thanks a lot.

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271
    If you have excel on your computer then in VB click on Project,
    Select References and check Microsoft Excel 5.0/9.0 whatever.
    This is from MSDN:

    CreateObject Function Example

    This example uses the CreateObject function to set a reference (xlApp) to Microsoft Excel. It uses the reference to access the Visible property of Microsoft Excel, and then uses the Microsoft Excel Quit method to close it. Finally, the reference itself is
    released.
    Code:
    Dim xlApp As Object   ' Declare variable to hold the reference.
       
    Set xlApp = CreateObject("excel.application")
       ' You may have to set Visible property to True
       ' if you want to see the application.
    xlApp.Visible = True
       ' Use xlApp to access Microsoft Excel's 
       ' other objects.
    xlApp.Quit   ' When you finish, use the Quit method to close 
    Set xlApp = Nothing   ' the application, then release the reference.
    PS. Make sure you set your objects=nothing, otherwise they'll
    gang up on you. Hope this helps.
    Sometimes what you're looking for is exactly where you left it.

  3. #3
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    321
    you could either use filesystemobject if you just want to read or use the automation method as described by johnvb6.

    another method of starting excel
    VB Code:
    1. Dim objexcel As Excel.Application
    2. Dim objbook As Excel.Workbook
    3. Dm objsheet As Excel.Worksheet
    4.  
    5. Set objexcel = New Excel.Application
    6. Set objbook = objexcel.Workbooks.Add
    7. Set objsheet = objexcel.Worksheets.Add

    the above is to create a new instance of excel. you can access the rows and columns using objsheet.cells(row,col) where row and col are integers.

    to open an existing excel file use the following

    VB Code:
    1. Set objbook = objexcel.Workbooks.Open("filename")

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    subdivision
    Posts
    7
    the codes given had really been very helpful. thanks a lot . I have another question though. Is there a way to know if the file ends or if it is the last row?

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