Board logo

標題: [發問] 薪資單合併列印後,轉成個別PDF並加密 [打印本頁]

作者: amihoim    時間: 2023-3-30 22:07     標題: 薪資單合併列印後,轉成個別PDF並加密

我的問題跟excel版這篇文有點類似
http://forum.twbts.com/viewthread.php?tid=19785

公司想要將薪資單,以電子郵件PDF加密的方式,寄給同仁。

大致想法是以excel(薪資計算單),與WORD(薪資格式檔)進行合併列印後,
匯成一張一張的PDF並加密,
再自動寄發電子郵件+挾帶薪資PDF文件,寄到員工本人的電子信箱。

請問該怎麼設計?  感謝各位大神
作者: Andy2483    時間: 2023-3-31 07:20

回復 1# amihoim


    謝謝前輩發表此主題與範例
建議前輩上傳薪資管理檔案和理想中的pdf檔
作者: linyancheng    時間: 2023-4-15 18:44

回復 1# amihoim


Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim password As String

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Your\Excel\File\Path.xls")
Set xlSheet = xlBook.Sheets("Sheet1")

password = xlSheet.Cells(2, 1).Value '取得第2列第1欄的值作為密碼

xlBook.Close SaveChanges:=False
xlApp.Quit

Dim password As String
Dim pdfFileName As String

'讀取Excel文件中的密碼欄位
'省略讀取Excel的程式碼

'設置PDF加密選項
Dim pdfSecurity As Object
Set pdfSecurity = CreateObject("AcroExch.PDDoc")
pdfSecurity.SetSecurity "user", "", 2, "", password, True '2代表128位AES加密

'轉換Word為PDF
pdfFileName = "C:\Your\PDF\File\Path.pdf"
ActiveDocument.ExportAsFixedFormat OutputFileName:=pdfFileName, ExportFormat:=wdExportFormatPDF, _
    OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
    Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
    CreateBookmarks:=wdExportCreateNoBookmarks, _
    DocumentStructureTags:=True, _
    SecurityDescriptor:=pdfSecurity

Dim i As Integer
Dim pageNum As Integer

'取得頁面總數
pageNum = ActiveDocument.ComputeStatistics(wdStatisticPages)

'遍歷每個頁面
For i = 1 To pageNum
    '在此添加將每一頁個別另存為加密PDF的程式




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)