|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub CommandButton5_Click()
Dim arr()
Dim rng As Range
ReDim arr(1 To 100000, 1 To 23)
If objListViewDemo1.ListItems.Count < 1 Then MsgBox "对不起!没有你想要导出的数据": Exit Sub
Set rng = ActiveSheet.Rows(1)
lj = CreateObject("wscript.shell").specialfolders.Item("desktop") & ("\")
For i = 1 To objListViewDemo1.ListItems.Count
If objListViewDemo1.ListItems(i).Checked = True Then
m = m + 1
arr(m, 1) = objListViewDemo1.ListItems(i)
For j = 1 To objListViewDemo1.ColumnHeaders.Count - 1
arr(m, j + 1) = objListViewDemo1.ListItems(i).SubItems(j) '
Next j
End If
Next i
If m = "" Then MsgBox "请先勾选需要导出的数据!": Exit Sub
Application.SheetsInNewWorkbook = 1
Set wb = Workbooks.Add
With wb.Worksheets(1)
rng.Copy .[a1]
.[a2].Resize(m, UBound(arr, 2)) = arr
For Each sp In .Shapes
sp.Delete
Next sp
.Columns("a:w").AutoFit
.UsedRange.Borders.LineStyle = 1
End With
wb.SaveAs Filename:=lj & "导出文件" & Format(Date, "yyyymmdd") & ".xlsx"
wb.Close
MsgBox "导出完毕!", 0, "提醒"
End Sub |
|