使用VBS将值放入单元格中

任何人都知道如何使用VBS在一个单元格的价值? 到目前为止,我有这个代码:

option explicit Dim objWorkbook, wb, ws,logname,user, objExcel,cell Const xlUp = -4162 Set objWorkbook = CreateObject("Excel.Application") set user = CreateObject("wscript.network") logname = user.Username objWorkbook.Visible = True Set wb = objWorkbook.Workbooks.Open("C:\test\test.xlsx") Set ws = wb.Worksheets(1) With ws .Range("A" & .Rows.Count).End(xlUp).Row 'put the value of logname .Range("A" & .Rows.Count).End(xlUp).Row 'put the value of date() .Range("A" & .Rows.Count).End(xlUp).Row 'put the value of time() End With 

执行代码后,它应该增加,以便在下一次插入数据时,要插入的数据将被插入到下一行而没有数据。 提前致谢!

试试下面。

 option explicit Dim objWorkbook, wb, ws,logname,user, objExcel,cell Const xlUp = -4162 Set objWorkbook = CreateObject("Excel.Application") set user = CreateObject("wscript.network") logname = user.Username objWorkbook.Visible = True Set wb = objWorkbook.Workbooks.Open("C:\test\test.xlsx") Set ws = wb.Worksheets(1) With ws Set cell = .Range("A" & .Rows.Count).End(xlUp) 'Get last cell in A cell.Offset(1,0).Value = logname 'put the value of logname in column A after last row of data cell.Offset(1,1).Value = Date 'put the value of date() in column B cell.Offset(1,2).Value = Time 'put the value of time() in column C End With