CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    Québec (Canada)
    Posts
    210

    Open Excel sheet and change value in cells

    I will like to open an Excel sheet and change value in cell by code VB.

    Thanks
    Redg


  2. #2
    Join Date
    Oct 1999
    Location
    US
    Posts
    34

    Re: Open Excel sheet and change value in cells

    public x as Excel.Application
    public withevents Book as Excel.Workbook
    public Sheet1 as Excel.Worksheet
    'in your func
    set x = CreateObject("excel.application")
    x.Visible = false
    set Book = x.Workbooks.Open(strNewDest)
    set Sheet1 = Book.Worksheets("Create")




    And then you can do anything like in VBA
    Or did you mean a recordset. It is possible too
    I did it in VC.


  3. #3
    Join Date
    Jan 2000
    Location
    CA
    Posts
    52

    Re: Open Excel sheet and change value in cells

    Or, more to the point, if you have an existing spreadsheet



    dim xlBook as new Excel.Workbook
    set xlBook = getObject(filename as string)
    dim xlSheet as Excel.worksheet
    set xlSheet = xlBook.Worksheets(1) 'Assuming the info is on sheet 1, could just put in the name as a string in the parentheses.
    xlsheet.Cells(1,3).Value = newvalue





    Cells(1,3) refers to the 3rd column of the first row. newValue is the value to put into this cell.

    This can also be done using the Range object

    xlSheet.Range("C1").value = newValue

    AS AndyK stated, you can work with all of the features of Excel. The best way to learn of the functionality available is to start Excel and start a VBA session (Tools|Macro|VB Editor), then open a Help window for Visual Basic for Microsoft Excel. Look at the Worksheets and Range or Cells Objects and explore the numerous properties available.

    Good Luck...


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