CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 1999
    Location
    Israel
    Posts
    5

    Working with Excel

    Hi,
    I would like to open an existing form of Excel and retreive information about it for example how many sheets, how many columns, rows etc..
    How can this be done??
    Thank-you!!

    LED

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: Working with Excel

    to connect your program to a running instance of Excel use the GetObject function in VB.
    Save the return value in an object variable and use Excel's object model to query it for all desired properties of all relevant objects.


  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: Working with Excel

    sample code from MSDN.
    Dim appXL As Excel.Application
    Set appXL = GetObject(, "Excel.Application")




  4. #4
    Join Date
    Nov 1999
    Location
    Israel
    Posts
    5

    Re: Working with Excel

    Hello,
    I need to know how to open an existing file for example c:\My Documents\abc.xls and if not exists then create it. Then I would like to run over it's sheets and columns and rows and modify / check what I need . Is there a code sample for this or an article in the MSDN disc?/
    Thanks


    LED

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: Working with Excel

    to open a file into excel, add a reference to the Excel typelibrary to your VB project and use the following code

    Dim x as Excel.Application
    Dim wb as Excel.Workbook
    set x = CreateObject("Excel.Application")
    set wb = x.Workbooks.Open("c:\test.txt")
    x.Visible = true
    ' now to the modifications and queries
    wb.Save ' save your modifications
    set x = nothing




    check out the Excel object model via the object browser in VB (F2)


  6. #6
    Join Date
    Nov 1999
    Location
    Israel
    Posts
    5

    Re: Working with Excel

    Hi Lothar,
    I need some more "specificness".
    1. What is a "workbook" of an Excel application?
    2. What does the method "CreateObject" do??
    3. What is the Set x = nothing stand for??
    4. What is F2 used for in this example?
    5. How do I close the Excel application afetr finishing all modifications?

    Thank-you again!!


    LED

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

Featured