任何人都知道如何使用VBScript检查单元格是否包含数据?由于我所看到的,它与VBA有点不同。我试过这段代码但是没有用:
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test\test.xlsx")
Set user = CreateObject("WScript.Network")
logname = user.Username
objExcel.Application.Visible = True
If Hour(Now) >= 1 And Hour(Now) =< 11 Then
WScript.Echo "Good Morning"
WScript.Echo "Log Record is:", Time, Date
lastrow = Range("A1").End(xlDown).Row
Cells(lastrow+1, 1).Value = logname
End If
检查行是否包含数据后,代码会将数据插入到不包含数据的下一行。我们会说:如果CELL A1
有数据,那么CELL A2
为空,那么要插入的数据将插入CELL A2
。
答案 0 :(得分:0)
使用UsedRange
属性:
Set ws = objExcel.ActiveSheet
With ws.UsedRange
nextrow = .Row + .Rows.Count
End With
Set cell = ws.Cells(nextrow, 1).Range("A1")
cell.Value = logname