Jump to content

3.3.12 Pass Variable of Last Row in ColB to _Excel_RangeRead


stealth
 Share

Recommended Posts

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 by stealth
Link to comment
Share on other sites

What is the value of @error after _Excel_RangeRead?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

@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 by stealth
Link to comment
Share on other sites

@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)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Great :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...