10-24-2019 06:56 AM
Hey,
do anyone know how i can get the last row in an Excel file?
I have wrote this but it doesnt work..
Dim str_SL, objExcel
Dim objWorkbook
str_SL = "C:\Root\Eve.xlsx"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(str_SL)
objExcel.Visible = false
MsgBox objExcel.Cells(Rows.Count, 2).End(xlUp).Row
10-25-2019 11:28 AM
Hi Dia_Nutzer,
Are you wanting to load data channels from an Excel file? In that case I'd recommend creating a new DataPlugin that uses the "Spreadsheet Reader". It has a built-in "Sheet.MaxPosition.Row" ability. DIAdem 2019 also has a new Excel file reader object that I'd recommend for reading out or writing to selected cells of an Excel file, if you're DIAdem version isn't earlier than 2019.
If you're stuck with ActiveX, this is a function I used way back when I had to lean on the Excel ActiveX object inside DataPlugins.
Function GetRangeArray(Sheet, StartLetter, StartRow, ColNumber) Dim iMax, Range, RangeArray Const xldown = -4121 On Error Resume Next Set Range = Sheet.Range(StartLetter & StartRow) Set Range = Range.Offset(0, 0) Set Range = Range.Resize(1, ColNumber) iMax = Range.End(xldown).Row Set Range = Range.Resize(iMax-StartRow+1, ColNumber) RangeArray = Range.Value IF Err.Number <> 0 THEN ReDim RangeArray(1, ColNumber) On Error Goto 0 GetRangeArray = RangeArray End Function ' GetRangeArray()
Brad Turpin
DIAdem Product Support Engineer
National Instruments