|
Sub 生成证件()
Application.ScreenUpdating = False
Set Sh = ThisWorkbook.Worksheets("上岗证")
f = Dir(ThisWorkbook.Path & "\PersonInfo.csv")
If f = "" Then MsgBox "数据源文件不存在": Exit Sub
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & f, 0)
With wb.Worksheets("PersonInfo")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a14:m" & rs)
End With
wb.Close False
ws = Sh.Cells(Rows.Count, 2).End(xlUp).Row + 10
For Each a In Sh.Shapes
a.Delete
Next
Sh.Rows("9:" & ws).Delete
Sh.Range("d2:d8,i2:i8") = Empty
m = 9
If (UBound(ar) - 1) / 2 = Int((UBound(ar) - 1) / 2) Then
k = Int((UBound(ar) - 1) / 2)
Else
k = Int((UBound(ar) - 1) / 2) + 1
End If
For i = 2 To k
Sh.Rows("1:8").Copy Sh.Cells(m, 1)
m = m + 8
Next i
ws = Sh.Cells(Rows.Count, 2).End(xlUp).Row
m = 2
For i = 2 To UBound(ar) Step 2
Sh.Cells(m, 4) = ar(i, 1)
Sh.Cells(m + 1, 4) = ar(i, 9)
Sh.Cells(m + 2, 3) = ar(i, 10)
Sh.Cells(m + 3, 3) = ar(i, 12)
Sh.Cells(m + 4, 4) = ar(i, 13)
Sh.Cells(m + 5, 4) = ar(i, 5)
Sh.Cells(m + 6, 4) = ar(i, 11)
fs1 = ThisWorkbook.Path & "\faces\" & Trim(ar(i, 1)) & "_" & Mid(ar(i, 5), 2, Len(ar(i, 5)) - 1) & ".jpg"
If Dir(fs1) <> "" Then
Sh.Select
Sh.Range("e" & m & ":e" & m + 6).Select
ActiveSheet.Pictures.Insert(fs1).Select
With Selection.ShapeRange
Selection.ShapeRange.LockAspectRatio = msoFalse
.Top = Sh.Range("e" & m & ":e" & m + 6).Top + 1
.Left = Sh.Range("e" & m & ":e" & m + 6).Left + 1
.Width = Sh.Range("e" & m & ":e" & m + 6).Width
.Height = Sh.Range("e" & m & ":e" & m + 6).Height
End With
End If
If i = UBound(ar) Then GoTo 10
Sh.Cells(m, 9) = ar(i + 1, 1)
Sh.Cells(m + 1, 9) = ar(i + 1, 9)
Sh.Cells(m + 2, 8) = ar(i + 1, 10)
Sh.Cells(m + 3, 8) = ar(i + 1, 12)
Sh.Cells(m + 4, 9) = ar(i + 1, 13)
Sh.Cells(m + 5, 9) = ar(i + 1, 5)
Sh.Cells(m + 6, 9) = ar(i + 1, 11)
fs1 = ThisWorkbook.Path & "\faces\" & Trim(ar(i + 1, 1)) & "_" & Mid(ar(i + 1, 5), 2, Len(ar(i + 1, 5)) - 1) & ".jpg"
If Dir(fs1) <> "" Then
Sh.Select
Sh.Range("j" & m & ":j" & m + 6).Select
ActiveSheet.Pictures.Insert(fs1).Select
With Selection.ShapeRange
Selection.ShapeRange.LockAspectRatio = msoFalse
.Top = Sh.Range("j" & m & ":j" & m + 6).Top + 1
.Left = Sh.Range("j" & m & ":j" & m + 6).Left + 1
.Width = Sh.Range("j" & m & ":j" & m + 6).Width
.Height = Sh.Range("j" & m & ":j" & m + 6).Height
End With
End If
m = m + 8
10:
Next i
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|