I have written a short script that logs the time in a spreadsheet when I login to my computer but I cannot define the last row properly. If I was writing in VBA the below would execute fine but I receive an error when the VBScript is executed.
VBScript is taking Rows from Rows.Count as a variable so it throws an error because I have Option Explicit on. If i try and qualify it as .Rows.Count it thinks xlup is a variable.
Do I need to reference the Excel Object library in the VBScript or should I just be using a different syntax altogether to find the LR in VBScript?
Option Explicit
Dim xlapp
Dim oWB
Dim oWS
Dim LR
Set xlapp = CreateObject("excel.application")
Set oWB = xlapp.Workbooks.Open("H:\HR Stuff\time_management.xls")
Set oWS = oWB.Sheets("Sheet1")
With oWS
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Cells(LR, 1).Value = Now
End With
oWB.Close True
xlapp.Quit
Set xlapp = Nothing
xlUp is a constant known to VBA, but not to VBScript. You have to define it yourself: