한 3년전에 인수한 법인이 회사규모가 작다보니
한명의 인원이 인사 회계 온갖 일을 하고있는겁니다.
얼마전에 연락이와서 진짜 일 짜친다 하길래
어디서 그런 시간을 많이잡아 먹냐 랴고 다시 물었습니다.
지금 급여명세서 만드는데 오래걸린다 하여, 급여명세서 양식과
데이터를 달라 하였고,
이를 C:\급여명세서 폴더에 사람이름별로 PDF 떠서 저장하는 매크로를 만들어 줬습니다.
예전에는 자동출력이었는데, 그 기능에서 조금 업그레이드 한 버전입니다.
이거 요즘 왠만한 급여작업하는 프로그램에서는 다 할텐데 인수당시에 담당자가 필요없다해서 이런 수고를 하는중이네요.
Sub start()
Dim r As Long
Dim shtPrint As Worksheet
Dim shtData As Worksheet
Dim rng(1 To 11) As Range
Dim fileName As String
Dim savePath As String
Dim folderPath As String
Set shtPrint = ThisWorkbook.Worksheets("출력물") ' 출력 양식
Set shtData = ThisWorkbook.Worksheets("급여데이터") ' 데이터 시트
' 출력물에 해당하는 셀 지정
Set rng(1) = shtPrint.Range("G4") ' 성명
Set rng(2) = shtPrint.Range("E7") ' 기본급
Set rng(3) = shtPrint.Range("K7") ' 국민연금
Set rng(4) = shtPrint.Range("K8") ' 건강보험
Set rng(5) = shtPrint.Range("K9") ' 장기요양보험
Set rng(6) = shtPrint.Range("K10") ' 고용보험
Set rng(7) = shtPrint.Range("K11") ' 소득세
Set rng(8) = shtPrint.Range("K12") ' 지방소득세
Set rng(9) = shtPrint.Range("E18") ' 지급총액
Set rng(10) = shtPrint.Range("J18") ' 공제총계
Set rng(11) = shtPrint.Range("G19") ' 실지급액
' 저장 경로 확인 및 폴더 생성
folderPath = "C:\급여명세서\"
If Dir(folderPath, vbDirectory) = "" Then MkDir folderPath
r = 0
Do While shtData.Cells(2 + r, 1).Value <> ""
' 데이터 매핑
rng(1).Value = shtData.Cells(2 + r, 1).Value ' 성명
rng(2).Value = shtData.Cells(2 + r, 3).Value ' 기본급
rng(3).Value = shtData.Cells(2 + r, 5).Value ' 국민연금
rng(4).Value = shtData.Cells(2 + r, 6).Value ' 건강보험
rng(5).Value = shtData.Cells(2 + r, 7).Value ' 장기요양보험
rng(6).Value = shtData.Cells(2 + r, 8).Value ' 고용보험
rng(7).Value = shtData.Cells(2 + r, 9).Value ' 소득세
rng(8).Value = shtData.Cells(2 + r, 10).Value ' 지방소득세
rng(9).Value = shtData.Cells(2 + r, 4).Value ' 지급총액
rng(10).Value = shtData.Cells(2 + r, 15).Value ' 공제총계
rng(11).Value = shtData.Cells(2 + r, 16).Value ' 실지급액
' 파일명: 성명 기반으로, 특수문자 제거
fileName = Replace(rng(1).Value, "\", "_")
fileName = Replace(fileName, "/", "_")
fileName = Replace(fileName, ":", "_")
fileName = Replace(fileName, "*", "_")
fileName = Replace(fileName, "?", "_")
fileName = Replace(fileName, """", "_")
fileName = Replace(fileName, "<", "_")
fileName = Replace(fileName, ">", "_")
fileName = Replace(fileName, "|", "_")
fileName = folderPath & fileName & ".pdf"
' PDF로 저장
shtPrint.ExportAsFixedFormat Type:=xlTypePDF, fileName:=fileName, Quality:=xlQualityStandard
r = r + 1
Loop
MsgBox "모든 급여명세서 PDF 저장이 완료되었습니다!", vbInformation
End Sub
쓰실분은 조금 뜯어고쳐서 쓰심됩니다.
붉은색으로 칠한 부분만 양식에 맞춰서 변경하심 될거같아요.
'엑셀' 카테고리의 다른 글
엑셀 매크로 몇 (1) | 2024.12.18 |
---|---|
다중 엑셀 복사하기 - 1 (1) | 2023.11.14 |
엑셀 매크로(기초) 값 복사 붙여넣기 (0) | 2022.12.28 |
엑셀 시트별로 각각 따로 저장하기 (0) | 2022.12.10 |
엑셀 여러파일 한개 파일로 합치기 (0) | 2022.12.10 |
댓글