在VB中怎样实现将采集的数据按行保存到一个excel文件中,也就是每次采集的数据存在excel的一行中
以下是我编的程序,只实现了每次采集数据的保存到一个新的excel中PrivateSubCmdsave_Click()DimXAsIntegerDimExcelAppAsO...
以下是我编的程序,只实现了每次采集数据的保存到一个新的excel中
Private Sub Cmdsave_Click()
Dim X As Integer
Dim ExcelApp As Object
X = MsgBox("是否保存更改?", vbYesNoCancel + vbExclamation, "VB 保存数据到中 Excel")
If X = 6 Then '单击“是”则保存
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
.Range("A1:J1") = Array(Format(Now, "yy/mm/dd,hh:mm:ss "), a(0),a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9))
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
ElseIf X = 7 Then '单击“否”则不保存
Cancel = 0
Else '单击“取消”则不退出程序
Cancel = 1
End If
End Sub 展开
Private Sub Cmdsave_Click()
Dim X As Integer
Dim ExcelApp As Object
X = MsgBox("是否保存更改?", vbYesNoCancel + vbExclamation, "VB 保存数据到中 Excel")
If X = 6 Then '单击“是”则保存
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
.Range("A1:J1") = Array(Format(Now, "yy/mm/dd,hh:mm:ss "), a(0),a(1),a(2),a(3),a(4),a(5),a(6),a(7),a(8),a(9))
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
ElseIf X = 7 Then '单击“否”则不保存
Cancel = 0
Else '单击“取消”则不退出程序
Cancel = 1
End If
End Sub 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询