在vb中text中的数据怎么样保存到excel

2024-11-24 18:15:09
推荐回答(1个)
回答1:

Option Explicit
Dim xlapp As Variant
Dim xlBook As Variant
Dim xlSheet As Variant
Dim i As Integer
Private Sub Command1_Click()
i = i + 1
xlSheet.Cells(1, i + 1) = Text1.Text
xlSheet.Cells(1, 1) = Time$
End Sub

Private Sub Form_Load()
Set xlapp = CreateObject("excel.application")
xlapp.Visible = True
Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.worksheets(1)
End Sub

Private Sub Form_Unload(Cancel As Integer)
xlapp.Quit '关闭EXCEL
Set xlapp = Nothing '释放EXCEL对象
End Sub