Sub outexcel()
Dim excelApp As Excel.Application
Set excelApp = New Excel.Application
On Error Resume Next
If excelApp Is Nothing Then
Set excelApp = CreateObject("Excel.application")
If excelApp Is Nothing Then
Exit Sub
End If
End If
excelApp.Visible = True
Me.MousePointer = vbHourglass
excelApp.Workbooks.Add
Dim n As Integer, x As Integer
n = formdata.ListView1.ListItems.Count
x = frmlist.ListView1.ListItems.Count
With excelApp.ActiveSheet
'生成excel
Dim i As Integer, j As Integer
For i = 2 To formdata.ListView1.ListItems.Count
For j = 1 To formdata.ListView1.ColumnHeaders.Count
.Cells(1, j).Value = formdata.ListView1.ColumnHeaders(j).Text
.Cells(i, 1).Value = formdata.ListView1.ListItems(i - 1).Text
.Cells(i, j + 1).Value = formdata.ListView1.ListItems(i - 1).SubItems(j)
Next j
DoEvents
Next i
End With
Me.MousePointer = vbDefault
Set excelApp = Nothing
' End With
End Sub
我想在显示出的excel中,以上的结果显示在sheet1中,可以实现!
我还想在该excel中的sheet2中插入另一个类似的表格!语句如何实现阿?
Dim excelApp As Excel.Application
Set excelApp = New Excel.Application
On Error Resume Next
If excelApp Is Nothing Then
Set excelApp = CreateObject("Excel.application")
If excelApp Is Nothing Then
Exit Sub
End If
End If
excelApp.Visible = True
Me.MousePointer = vbHourglass
excelApp.Workbooks.Add
Dim n As Integer, x As Integer
n = formdata.ListView1.ListItems.Count
x = frmlist.ListView1.ListItems.Count
With excelApp.ActiveSheet
'生成excel
Dim i As Integer, j As Integer
For i = 2 To formdata.ListView1.ListItems.Count
For j = 1 To formdata.ListView1.ColumnHeaders.Count
.Cells(1, j).Value = formdata.ListView1.ColumnHeaders(j).Text
.Cells(i, 1).Value = formdata.ListView1.ListItems(i - 1).Text
.Cells(i, j + 1).Value = formdata.ListView1.ListItems(i - 1).SubItems(j)
Next j
DoEvents
Next i
End With
Me.MousePointer = vbDefault
Set excelApp = Nothing
' End With
End Sub
我想在显示出的excel中,以上的结果显示在sheet1中,可以实现!
我还想在该excel中的sheet2中插入另一个类似的表格!语句如何实现阿?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货