|
本帖最后由 microyip 于 2022-4-2 23:02 编辑
- Sub 工资条图片生成()
- Dim oPic As Object, oShape As Object
- Dim vData As Variant, nRow As Long, vFill As Variant
- Dim wActSH As Worksheet, wSH As Worksheet
-
- Application.ScreenUpdating = False
- With Sheet1
- On Error Resume Next
- Set wSH = Sheets("工资表模版")
- If Err.Number <> 0 Then
- Set wSH = Sheets.Add(after:=Sheets(Sheets.Count))
- wSH.Name = "工资表模版"
- End If
- On Error GoTo 0
- With wSH
- .Activate
- For Each oShape In .Shapes
- oShape.Delete
- Next
- .Cells.Delete
- End With
-
- vData = .UsedRange.Resize(, 27).Value
- .[A1:AA3].Copy
- With wSH
- .[A1].PasteSpecial , Transpose:=True
- .[A1:B1].EntireColumn.AutoFit
- .[C1].EntireColumn.ColumnWidth = 9.25
- With .[A1:C27]
- .VerticalAlignment = xlVAlignCenter
- .HorizontalAlignment = xlHAlignCenter
- .Copy
- End With
- .[E1].Activate
- Set oShape = .Pictures.Paste(Link:=True)
- .[J1].Activate
- For nRow = 2 To UBound(vData)
- If vData(nRow, 1) <> "" Then
- .[C1].Resize(UBound(vData, 2)) = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(vData, nRow))
- oShape.Copy
- .PasteSpecial Format:="图片(增强型图元文件)", Link:=False, DisplayAsIcon:=False
- For Each oPic In .Shapes
- If oPic.Name <> oShape.Name Then Exit For
- Next
- With .ChartObjects.Add(0, 0, oPic.Width, oPic.Height).Chart
- .Paste
- .Export ThisWorkbook.Path & "" & vData(nRow, 1) & "(" & vData(1, 2) & ").jpg"
- .Parent.Delete
- End With
- oPic.Delete
- End If
- Next
- oShape.Delete
- End With
- .Activate
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|