VB6.0中,怎么才能点击按钮清空在程序保存的进Excel中的记录(第二行到最后),再在程序中保存的时候能够从第二行开始保存,再存还是一条一条的往下继续,不会还是从原来保存的地方的下一行开始保存(上面是空的)
保存数据代码:
Private Sub Command1_Click() '保存当前数据
Dim sVal As String
Dim k2 As Integer Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open("E:\评分.xlsx")
Set xlsheet = xlbook.Worksheets(1) If k1 <= 0 Then
k2 = 2
sVal = Trim(xlsheet.Cells(k2, 1) & xlsheet.Cells(k2, 2))
Do While sVal <> ""
k2 = k2 + 1
sVal = Trim(xlsheet.Cells(k2, 1) & xlsheet.Cells(k2, 2))
Loop
k1 = k2
End If
xlsheet.Cells(k1, 1) = Text1.Text
xlsheet.Cells(k1, 2) = Text2.Text
xlsheet.Cells(k1, 3) = Text3.Text
xlsheet.Cells(k1, 4) = Text4.Text
xlsheet.Cells(k1, 5) = Text5.Text
xlsheet.Cells(k1, 6) = Text6.Text
xlsheet.Cells(k1, 7) = Text7.Text
xlsheet.Cells(k1, 8) = Text8.Text
xlsheet.Cells(k1, 9) = Text9.Text
xlsheet.Cells(k1, 10) = Text10.Text
xlsheet.Cells(k1, 11) = Text11.Text
xlsheet.Cells(k1, 12) = Text12.Text
xlsheet.Cells(k1, 13) = Label23.Caption
xlsheet.Cells(k1, 14) = Label24.Caption
k1 = k1 + 1 xlbook.Saved = True
xlbook.Save On Error Resume Next xlapp.Quit
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing MsgBox "save success!", vbInformation + vbOKOnly, "note"
End Sub
保存数据代码:
Private Sub Command1_Click() '保存当前数据
Dim sVal As String
Dim k2 As Integer Set xlapp = CreateObject("excel.application")
Set xlbook = xlapp.Workbooks.Open("E:\评分.xlsx")
Set xlsheet = xlbook.Worksheets(1) If k1 <= 0 Then
k2 = 2
sVal = Trim(xlsheet.Cells(k2, 1) & xlsheet.Cells(k2, 2))
Do While sVal <> ""
k2 = k2 + 1
sVal = Trim(xlsheet.Cells(k2, 1) & xlsheet.Cells(k2, 2))
Loop
k1 = k2
End If
xlsheet.Cells(k1, 1) = Text1.Text
xlsheet.Cells(k1, 2) = Text2.Text
xlsheet.Cells(k1, 3) = Text3.Text
xlsheet.Cells(k1, 4) = Text4.Text
xlsheet.Cells(k1, 5) = Text5.Text
xlsheet.Cells(k1, 6) = Text6.Text
xlsheet.Cells(k1, 7) = Text7.Text
xlsheet.Cells(k1, 8) = Text8.Text
xlsheet.Cells(k1, 9) = Text9.Text
xlsheet.Cells(k1, 10) = Text10.Text
xlsheet.Cells(k1, 11) = Text11.Text
xlsheet.Cells(k1, 12) = Text12.Text
xlsheet.Cells(k1, 13) = Label23.Caption
xlsheet.Cells(k1, 14) = Label24.Caption
k1 = k1 + 1 xlbook.Saved = True
xlbook.Save On Error Resume Next xlapp.Quit
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing MsgBox "save success!", vbInformation + vbOKOnly, "note"
End Sub