|
本帖最后由 quqiyuan 于 2024-12-15 19:39 编辑
代码如下。。。。
Sub test()
Dim arr, d, k, i%, j%
Dim sht As Worksheet
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Title = "请选择PDF文件保存的文件夹。。。"
.InitialFileName = ThisWorkbook.Path & "\"
If .Show Then folderPath = .SelectedItems(1) & "\" Else Exit Sub
End With
With ThisWorkbook.Sheets("成绩")
i = .Cells(.Rows.Count, 1).End(3).Row
Set d = CreateObject("scripting.dictionary")
arr = .Range("A1:L" & i)
For i = 3 To UBound(arr)
If Not d.exists(arr(i, 1)) Then Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
d(arr(i, 1))(i) = ""
Next
kk = d.keys
For Each k In d.keys
Worksheets.Add after:=ThisWorkbook.ActiveSheet
.Range("a1:l2").Copy ActiveSheet.Range("A1")
.Range("a1:l2").Copy
ActiveSheet.Range("A1").PasteSpecial xlPasteColumnWidths
Application.CutCopyMode = False
ActiveSheet.Name = k
n = 0
r = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(3).Row + 1
ReDim brr(1 To 10000, 1 To UBound(arr, 2))
For Each Key In d(k).keys
n = n + 1
For j = 1 To UBound(arr, 2)
brr(n, j) = arr(Key, j)
Next
Next
ActiveSheet.Cells(r, 1).Resize(n, UBound(arr, 2)) = brr
fileName = k & ".pdf"
' ActiveSheet.PageSetup.PrintArea = ActiveSheet.[a1].CurrentRegion.Address
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
folderPath & "\" & fileName, OpenAfterPublish:=False
Next
.Activate
End With
Set d = Nothing
Application.ScreenUpdating = True
End Sub
|
评分
-
2
查看全部评分
-
|