|
楼主 |
发表于 2024-3-16 14:22
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub GeneratePaySlip()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Fs, ReadSheet As Worksheet, Rng As Range, DateS As String, SavePath As String, FileS As String, RowsCount As Long, ColumnsCount As Long, K As Long, JD_All As Long, JD_Now As Long
Set Fs = CreateObject("Scripting.FileSystemObject")
If Fs.FolderExists(ThisWorkbook.Path & "\工资条") = False Then Fs.CreateFolder (ThisWorkbook.Path & "\工资条")
DateS = ActiveSheet.Name
ActiveSheet.Copy , Sheets(Sheets.Count)
Set ReadSheet = Sheets(Sheets.Count)
RowsCount = ReadSheet.UsedRange.Rows.Count
If RowsCount > 1 Then
ColumnsCount = ReadSheet.UsedRange.Columns.Count
ReadSheet.Rows("1:" & RowsCount).RowHeight = 20
ReadSheet.Rows("1:" & RowsCount).Font.Bold = True
For K = RowsCount To 3 Step -1 '对第K行插入一行。
ReadSheet.Cells(K, 1).Resize(1, 1).EntireRow.Insert
Next
RowsCount = ReadSheet.UsedRange.Rows.Count
ReadSheet.Rows("1:1").Copy
Set Rng = ReadSheet.Rows(3)
For K = 3 To RowsCount Step 2
Set Rng = Union(Rng, ReadSheet.Rows(K))
Next
Rng.Select
ReadSheet.Paste
SavePath = ThisWorkbook.Path & "\工资条\"
JD_All = Int(RowsCount / 2)
On Error GoTo ExitLine
For K = 2 To RowsCount Step 2
FileS = ReadSheet.Cells(K, 2) & "(" & DateS & ")工资条"
ReadSheet.Range(ReadSheet.Cells(K - 1, 1), ReadSheet.Cells(K, ColumnsCount)).Copy
ReadSheet.Pictures.Paste.Select
With Selection
.Copy
With ReadSheet.ChartObjects.Add(0, 0, .Width, .Height).Chart
.Paste
.Export FileName:=SavePath & FileS & ".jpg", FilterName:="jpg"
' .Export FileName:=SavePath & FileS & ".png", FilterName:="png"
' .Export FileName:=SavePath & FileS & ".bmp", FilterName:="bmp"
.Parent.Delete
End With
.Delete
End With |
|