下面是将表格控件中的数据写到EXCEL中的一段代码,希望对你有所帮助!Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim tmpRow As Long Dim tmpCol As Integer On Error GoTo ExcelError Screen.MousePointer = vbArrowHourglass If khyGrid.Cols = 2 Or khyGrid.Rows = 3 Then MsgBox "数据格式不对,请计算后再保存", vbOKCancel, "保存提示" Exit Sub Else Set xlApp = CreateObject("excel.application") Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.Sheets(1) For tmpRow = 0 To khyGrid.Rows - 1 For tmpCol = 0 To khyGrid.Cols - 1 tmpTz = DoEvents() If tmpBreak = True Then tmpBreak = False Exit Sub End If s = khyGrid.TextArray(rocos(tmpRow, tmpCol, khyGrid.Cols)) xlSheet.Cells(tmpRow + 1, tmpCol + 1) = s Next Next xlApp.Visible = True Screen.MousePointer = 0 Exit Sub End If
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim tmpRow As Long
Dim tmpCol As Integer
On Error GoTo ExcelError Screen.MousePointer = vbArrowHourglass
If khyGrid.Cols = 2 Or khyGrid.Rows = 3 Then
MsgBox "数据格式不对,请计算后再保存", vbOKCancel, "保存提示"
Exit Sub
Else
Set xlApp = CreateObject("excel.application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Sheets(1)
For tmpRow = 0 To khyGrid.Rows - 1
For tmpCol = 0 To khyGrid.Cols - 1
tmpTz = DoEvents()
If tmpBreak = True Then
tmpBreak = False
Exit Sub
End If
s = khyGrid.TextArray(rocos(tmpRow, tmpCol, khyGrid.Cols))
xlSheet.Cells(tmpRow + 1, tmpCol + 1) = s
Next
Next
xlApp.Visible = True
Screen.MousePointer = 0
Exit Sub
End If