- 帖子
- 835
- 主題
- 6
- 精華
- 0
- 積分
- 915
- 點名
- 0
- 作業系統
- Win 10,7
- 軟體版本
- 2019,2013,2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2010-5-3
- 最後登錄
- 2024-11-14
|
4#
發表於 2016-5-1 05:10
| 只看該作者
本帖最後由 luhpro 於 2016-5-1 05:16 編輯
回復 3# kathych - Private Sub cbCreat_Click()
- Dim iCol%, iCols%
- Dim lSRow&, lTRow&
- Dim sPath$, sStr1$, sStr2$
- Dim wsTar As Worksheet
- Dim vD As Object
-
- Set vD = CreateObject("Scripting.Dictionary")
- sPath = ThisWorkbook.Path
- ChDrive sPath
- ChDir sPath
-
- With Sheets("總表")
- iCols = .Cells(2, Columns.Count).End(xlToLeft).Column
- iCol = 1
- While iCol <= iCols
- If .Cells(2, iCol) <> "" Then vD(Trim(.Cells(2, iCol))) = iCol
- iCol = iCol + 1
- Wend
-
- lSRow = 3
- While .Cells(lSRow, 1) <> ""
- Set wsTar = Sheets(CStr(.Cells(lSRow, 2)))
- With wsTar
- .[C2:C14].ClearContents
- .[E3:E14].ClearContents
- With .[E2] ' 月底那週就可以產生次月的薪資條
- .NumberFormat = "mmm.,yyyy"
- .Value = Now() - 7
- End With
- End With
-
- wsTar.[C2] = .Cells(lSRow, vD("員工姓名"))
-
- lTRow = 3
- Do While 1
- If wsTar.Cells(lTRow, 2) <> "" Or wsTar.Cells(lTRow, 4) <> "" Then
- sStr1 = Trim(wsTar.Cells(lTRow, 2))
- If sStr1 = "Total" Then Exit Do ' 遇到 Total 跳出迴圈
- sStr2 = Trim(wsTar.Cells(lTRow, 4))
- If sStr1 <> "" Then wsTar.Cells(lTRow, 3) = .Cells(lSRow, vD(sStr1))
- If sStr2 <> "" Then wsTar.Cells(lTRow, 5) = .Cells(lSRow, vD(sStr2))
- End If
- lTRow = lTRow + 1
- Loop
-
- With wsTar
- .Copy ' 經實測,本行跳行時會另產生一個工作簿並貼上第一個工作表, 所以可以不用加 PasteSpecial 指令
- With ActiveSheet
- .Name = "薪資條"
- With .Parent
- .SaveAs wsTar.[C2] & "-" & Format(wsTar.[E2], "yyyymm") & "薪資條.xls"
- .Close
- End With
- End With
-
- .PrintPreview
- ' 這裡放轉成PDF檔的指令,還沒測試出來怎麼做
-
- .[C2:C14].ClearContents
- .[E3:E14].ClearContents
- End With
- lSRow = lSRow + 1
- Wend
- End With
- End Sub
複製代碼
Test2-a.zip (17.51 KB)
|
|