'导出数据到Excel中
Private Sub cmdOutput_Click()
Dim objFileSystem As Object
Dim objExcelText As Object
Dim ss As String
Dim i, j As Integer
Dim num As Integer
num = 1
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("D:\材料追踪.xls")
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Activate
'将数组中的数据逐个复制到Ecxel报表的单元格中
For i = 1 To (aNum - 1) / 5 ' aNum-1是个全局变量,数值从 cmdOK_Click()事件中得到,表示数组的大小
For j = 1 To 5
xlsheet.Cells(4 + i, j) = a(num)
num = num + 1
Next
Next
xlsheet.Cells(2, 5) = Format(Now, "AMPM(YYYY-MM-DD hh:mm:ss)")
xlBook.RunAutoMacros (xlAutoOpen)
cmDialog.CancelError = False
cmDialog.FileName = "材料使用情况跟踪表"
cmDialog.DialogTitle = "Save Export File"
cmDialog.DefaultExt = "*.xls"
strFileName = cmDialog.FileName
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
msg = MsgBox("成功导出!", vbOKOnly)
End Sub