|
此函数封装了一些操作Excel表的操作,这里只作抛砖引玉,与大家一起进步...
Function GetValueFromExcelFile(sFilePath As String, sSheet As String, iRow As Integer, sColumn As String)
' sFilePath type = string FullPath of the Xls File
' sSheet type = string Name of the specific sheet
' iRow type = integer Number of the row for determinate a specific cell
' sColumn type = string Letter of the column for determinate a specific cell
Dim oExcelObj As Object
Dim oNewSheet As Object
Set oExcelObj = CreateObject("Excel.Application")
oExcelObj.WorkBooks.Open sFilePath
Set oNewSheet = oExcelObj.Sheets.Item(sSheet )
GetValueFromExcelFile= oNewSheet.Cells(iRow,sColumn)
oExcelObj.ActiveWorkBook.save
Set oNewSheet = Nothing
oExcelObj.Application.Quit
Set oExcelObj = Nothing
End Function
sub main
msgbox GetValueFromExcelFile("c:\\123.xls", "InputData", 2, "firstNum")
end sub |
|