假设另一个指定文件为b.xls,与代码所在工作簿处于同一文件夹中。。
时间和textbox内容要分别写入到其Sheet1的A、B两列
则该按钮的代码为
Private Sub CommandButton1_Click()
Dim wb As Workbook, aR As Long, bR As Long
Set wb = Workbooks.Open(ThisWorkbook.Path & "\b.xls", , False)
With wb.Worksheets(1)
aR = IIf(Application.CountA(.Range("A:A")) = 0, 1, .Cells(Rows.Count, 1).End(3).Row + 1)
bR = IIf(Application.CountA(.Range("B:B")) = 0, 1, .Cells(Rows.Count, 1).End(3).Row + 1)
.Cells(aR, 1) = Format(Now, "yyyy-mm-dd hh:mm:ss")
.Cells(bR, 2) = TextBox1.Text
End With
wb.Close True
TextBox1 = ""
End Sub