返回列表 上一主題 發帖

[發問] 薪資單合併列印後,轉成個別PDF並加密

[發問] 薪資單合併列印後,轉成個別PDF並加密

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

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

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

請問該怎麼設計?  感謝各位大神

回復 1# amihoim


    謝謝前輩發表此主題與範例
建議前輩上傳薪資管理檔案和理想中的pdf檔
用行動裝置瀏覽論壇學習很方便,謝謝論壇經營團隊
請大家一起上論壇來交流

TOP

回復 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的程式
Word呈現極致的靜態之美,Excel展現極致的動態之美。

TOP

        靜思自在 : 【蒙蔽的自由】人常在什麼都可以自由自在的時候,卻被這種隨心所欲的自由蒙蔽,虛擲時光而毫無覺知。
返回列表 上一主題