I'm making great use of the following code example Marcus provided...
Code: Select all
VBSTART
Dim xlApp
Dim xlBook
'Opens the Excel file in Excel
Sub OpenExcelFile(filename)
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = true
Set xlBook = xlApp.Workbooks.open(filename)
end sub
'Use this to close Excel later
Sub CloseExcel
xlApp.quit
Set xlApp = Nothing
End Sub
'Retrieves a cell value from the specified
'worksheet
Function GetCell(Sheet,Row,Column)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
GetCell = xlSheet.Cells(Row, Column).Value
End Function
'Sets specified cell of specified worksheet
Function SetCell(Sheet,Row,Column,NewValue)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
xlSheet.Cells(Row,Column).Value = NewValue
End Function
VBEND
Code: Select all
'Gets last active row of specified worksheet
Function LastRow(Sheet,Column)
Dim xlSheet
Set xlSheet = xlBook.Worksheets(Sheet)
LastRow = xlSheet.LastRow.UsedRange.Rows.Count
End Function
This will be a very useful function for a lot of list management or list-based processing routines reliant upon Excel.