|
从表格中提取图片不知道如何操作,如果你的图片是和“数据”文件放在一个文件夹,就可以使用以下代码:
Sub 批量导出到模板3()
Dim ar, br, cr, i%, j%, wb1 As Workbook, wb2 As Workbook, wb As Workbook, d As Object, shp As Shape
Set wb1 = ThisWorkbook
' sheet2.Shapes
ar = wb1.Sheets("数据").Range("a2:il" & Cells(Rows.Count, 1).End(xlUp).Row)
ReDim br(1 To UBound(ar) + 1, 1 To UBound(ar, 2))
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(ar)
For j = 1 To UBound(ar, 2)
br(1, j) = Replace(Cells(1, j).Address(False, False), "1", "") & "列"
If ar(i, j) = "" Then
Else
br(i + 1, j) = ar(i, j)
End If
Next j
Next i
Set wb2 = Workbooks.Open(wb1.Path & "\模板1.xls")
For m = 1 To UBound(ar)
For j = 2 To UBound(br, 2)
d(br(m + 1, 1) & "-" & br(1, j)) = br(m + 1, j)
Next j
Set wb = Workbooks.Add
wb2.Sheets.Copy before:=wb.Sheets(1)
With wb.Sheets("工作表1")
cr = .Range("a3:k45")
For i = 1 To UBound(cr)
For j = 1 To UBound(cr, 2)
If Right(cr(i, j), 1) = "列" Then
If cr(i, j) <> "L列" Then
.Cells(i + 2, j) = d(ar(m, 1) & "-" & cr(i, j))
Else
' a = .Range("j30").RowHeight * 13
' b = .Range("j30").ColumnWidth * 2
p = wb1.Path & "\" & ar(m, 12) & ".jpg"
Set rng = .Range("j30:k42")
.Shapes.AddPicture p, True, True, rng.Left, rng.Top, rng.Width, rng.Height
End If
ElseIf cr(i, j) = "箱 内 设 备 清 单" Then
For s = 1 To 21
.Cells(i + s + 2, j + 2) = ar(m, 5 * (s - 1) + 17)
.Cells(i + s + 2, j + 3) = ar(m, 5 * (s - 1) + 18)
.Cells(i + s + 2, j + 4) = ar(m, 5 * (s - 1) + 19)
.Cells(i + s + 2, j + 5) = ar(m, 5 * (s - 1) + 20)
.Cells(i + s + 2, j + 6) = ar(m, 5 * (s - 1) + 21)
Next s
Else
End If
Next j
Next i
.Cells(10, 20).Value = ar(m, 1) '
End With
wb.SaveAs (wb1.Path & "\" & ar(m, 2) & ".xlsx")
wb.Close
d.RemoveAll
Next m
MsgBox "导出完毕!"
End Sub
|
|