Option Explicit
Function myDate(sname$)
Dim arr
arr = Sheet2.UsedRange.Value
Dim dic
Set dic = CreateObject("scripting.dictionary")
Dim n%, i%, r%, j%
n = Sheet2.Cells(Rows.Count, 2).End(xlUp).Row
For i = 4 To n
dic(arr(i, 2)) = i
Next
r = dic(sname)
ReDim brr(1 To 12, 1 To 4)
For j = 1 To 4
brr(1, j) = arr(r, j + 2)
brr(2, j) = arr(r, j + 6)
brr(3, j) = arr(r, j + 10)
brr(4, j) = arr(r, j + 14)
brr(5, j) = arr(r, j + 18)
brr(6, j) = arr(r, j + 22)
brr(7, j) = arr(r, j + 26)
brr(8, j) = arr(r, j + 30)
brr(9, j) = arr(r, j + 34)
brr(10, j) = arr(r, j + 38)
brr(11, j) = arr(r, j + 42)
brr(12, j) = arr(r, j + 46)
Next
With Sheet1
.Range("D4").Resize(12, 4) = brr
.Cells(16, 3) = arr(r, 53)
.Cells(17, 3) = arr(r, 54)
.Cells(17, 5) = arr(r, 55)
.Cells(17, 7) = arr(r, 56)
.Cells(18, 3) = arr(r, 57)
.Cells(18, 6) = arr(r, 58)
.Cells(19, 2) = arr(r, 59)
.Cells(21, 2) = arr(r, 60)
End With
End Function
Sub savename()
Dim i%, n%
Dim arr
n = Sheet2.Cells(Rows.Count, 2).End(xlUp).Row
arr = Array("科目1", "科目2", "科目3", "科目4", "科目5", "科目6", "科目7", "科目8", "科目9", "科目10", "科目11", "科目12")
Sheet1.Range("A4:A15") = Application.Transpose(arr)
For i = 4 To n
Sheet1.Cells(2, 6) = Sheet2.Cells(i, 2)
myDate (Sheet1.Cells(2, 6).Value)
Sheet1.Copy
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Sheet1.Cells(2, 6).Value & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
ActiveWorkbook.Close False
Next
End Sub
|