stealth Posted November 17, 2014 Share Posted November 17, 2014 (edited) While using 3.3.8, this worked fine: Local $fFile = "C:\Users\" & @UserName & "\Documents\test.xlsx" If Not FileExists($fFile) Then MsgBox(0, "Excel File Test", "Can't run this script b/c you don't have " & @CRLF & $fFile & " open") Exit EndIf $oExcel = ObjGet("", "Excel.Application") ;Gets an existing Excel Object If @error Then ;Error traps if Excel file is not open MsgBox(0, "ExcelFileTest", "You don't have Excel running at this moment. Error code: " & Hex(@error, 8)) Exit EndIf $oExcelDoc = ObjGet($fFile) ;Get an Excel Object from an existing filename $dDdoc = $oExcel.Sheets("Sheet1") ;dim the Workbook's sheet Global Const $xlUp = -4162 ;global constant for Excel up, finding last row $LNC = $oExcel.Sheets("Sheet1").Range("B65535").End($xlUp).Row ;dims last row in Excel Col B I'm unable to pass variable $LNC (last empty cell in ColumnB) to _Excel_RangeRead. What am I doing wrong? Is Global Const $xlUp = -4162 still valid in 3.3.12? $oAppl = _Excel_Open() $sWorkbook = "C:\Users\" & @UserName & "\Documentstest.xlsx" $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook, Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Dim $LNC Global Const $xlUp = -4162 ;global constant for Excel up, finding last row $LNC = $oWorkbook.ActiveSheet.Range("B65535").End($xlUp).Row ;dims last row in Excel Col B $sResult = _Excel_RangeRead($oWorkbook, Default, $LNC, 1) MsgBox(0, "last row", $sResult) Thank you in advance. Edited November 18, 2014 by stealth Link to comment Share on other sites More sharing options...
water Posted November 17, 2014 Share Posted November 17, 2014 What is the value of @error after _Excel_RangeRead? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
stealth Posted November 17, 2014 Author Share Posted November 17, 2014 (edited) @error 3 @extended -2147352567 $LNC = $oWorkbook.ActiveSheet.Range("B65535").End($xlUp).Row ;dims last row in Excel Col B Msgbox(0, "last row", $LNC) Correctly returns value of the last Cell in Column B. However, I'd like to pass the cell address as a variable to _Excel_RangeRead and that's where I'm stuck. Edited November 17, 2014 by stealth Link to comment Share on other sites More sharing options...
water Posted November 17, 2014 Share Posted November 17, 2014 @error = 3 means: $vRange is invalid. Correctly returns value of the last Cell in Column B. As far as I understand your code does not return the value of the last cell in column B but the row number of the last cell in column B. Could you please try: $oAppl = _Excel_Open() $sWorkbook = "C:\Users\" & @UserName & "\Documentstest.xlsx" $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook, Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Dim $LNC Global Const $xlUp = -4162 ;global constant for Excel up, finding last row $LNC = $oWorkbook.ActiveSheet.Range("B65535").End($xlUp) $sResult = _Excel_RangeRead($oWorkbook, Default, $LNC, 1) MsgBox(0, "last row", $sResult) stealth 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
stealth Posted November 17, 2014 Author Share Posted November 17, 2014 Sorry, typo on my part. "Correctly returns Row Number of the last Cell in Column B." Let me try your suggestion. Thanks Link to comment Share on other sites More sharing options...
stealth Posted November 18, 2014 Author Share Posted November 18, 2014 Thank you, Water! It worked Link to comment Share on other sites More sharing options...
water Posted November 18, 2014 Share Posted November 18, 2014 Great My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now