请教VB msflexgrid控件导出到excel表格问题
界面有两个msflexgrid表格,点击command控件(只有一个)输出到excel表格。问题是:1.excel中两个表格是相互独立的,我想做到一个excel里面。2.excel表格无法调节适合大小。刚输来的有点凌乱。请教大神!!!
Dim a As Integer
Dim b As Integer
Dim d As Integer
On Error GoTo Ert
Me.MousePointer = 11
Dim Excelapp As Excel.Application
Set Excelapp = New Excel.Application
On Error Resume Next
DoEvents
Excelapp.SheetsInNewWorkbook = 1
Excelapp.Workbooks.Add
Excelapp.ActiveSheet.Cells(1, 3) = s
Excelapp.Range("C1").Select
Excelapp.Selection.Font.FontStyle = "Bold"
Excelapp.Selection.Font.Size = 16
Excelapp.Caption = "输出表格"
With MSFlexGrid1
d = MSFlexGrid1.Rows
For a = 0 To d - 1
For b = 0 To 5
DoEvents
Excelapp.ActiveSheet.Cells(3 + a, b + 1) = "'" & .TextMatrix(a, b)
Next b
Next a
End With
Me.MousePointer = 0
Excelapp.Visible = True
' Excelapp.Sheets.PrintPreview
Excelapp.Cells.EntireColumn.AutoFit
Ert:
If Not (Excelapp Is Nothing) Then
Excelapp.Quit
End If
Dim e As String
Dim f As Integer
Dim m As Integer
Dim n As Integer
On Error GoTo Ert2
Me.MousePointer = 11
Dim Excelapp2 As Excel.Application
Set Excelapp2 = New Excel.Application
On Error Resume Next
DoEvents
Excelapp2.SheetsInNewWorkbook = 1
Excelapp2.Workbooks.Add
Excelapp2.ActiveSheet.Cells(1, 3) = e
Excelapp2.Range("C1").Select
Excelapp2.Selection.Font.FontStyle = "Bold"
Excelapp2.Selection.Font.Size = 16
Excelapp2.Caption = "合计表格"
With MSFlexGrid2
n = MSFlexGrid2.Rows
For f = 0 To n - 1
For m = 0 To 5
DoEvents
Excelapp2.ActiveSheet.Cells(3 + f, m + 1) = "'" & .TextMatrix(f, m)
Next m
Next f
End With
Me.MousePointer = 0
Excelapp2.Visible = True
' Excelapp2.Sheets.PrintPreview
Excelapp2.Cells.EntireColumn.AutoFit
Ert2:
If Not (Excelapp2 Is Nothing) Then
Excelapp2.Quit
我写的是这样 出来的Excel表格是两个 我希望写到一个表格里面
谢谢你