VB如何获得当前计算机的日期,并写入excel表格内某一单元格

2024-12-05 00:31:06
推荐回答(4个)
回答1:

Private Sub Command1_Click()
Dim objExcel As Object
Dim t As String '定义时间变量
Dim p As String '定义文件路径与文件名
Dim s As String '定义表名

'例如你的文件在c:\book1.xls,表为sheet1
t = Time
p = "c:\book1.xls"
s = "sheet1"
Set objExcel = CreateObject("Excel.Application")
Set xlbook = objExcel.Workbooks.Open(p)
Set xlsheet = xlbook.Worksheets(s)
objExcel.Visible = True '设置表可见或不可见
xlsheet.cells(1, 1) = t
Set xlsheet = Nothing
Set xlbook = Nothing
Set objExcel = Nothing

End Sub

回答2:

用得着么??还是有其它用??
其实你在想要取当前日期的单元格中输入:
=now()
就行了的

回答3:

Cells(R,C)=date()

回答4:

=now