I will like to open an Excel sheet and change value in cell by code VB.
Thanks
Redg
Printable View
I will like to open an Excel sheet and change value in cell by code VB.
Thanks
Redg
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.
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...