|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
上月因为电信缴费转我这里处理,缴费后收了上百个电子发票,都是PDF文件,傻眼了,写了个VBA去利用Acrobat的打印功能批量打印,结果出来的全部是A4纸,又因赶时间报销处理,就不理了,直接交财务,结果……不过最后就那样算了。
本月又来了,研究了一下,直接打印,很难设定打印纸型,换个思路咯,把PDF文件导出图片,然后引入Excel打印,方便修改尺寸,结果发现引入图片后,刚好是比A5纸大一点点,于是把引入的页面调整为95%打印,出来的效果超好。特意分享给大家使用,如果大家有更好的方法,不妨也分享一下。
- Sub PrintInvoice()
- Dim vFile As Variant, sPath As String, sPDF As String, nI As Integer
- Dim acroApp As Acrobat.acroApp
- Dim acroAVDoc As Acrobat.acroAVDoc
- Dim acroPDDoc As Acrobat.acroPDDoc
- Dim oJSO As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- vFile = Application.GetOpenFilename("PDF 文件,*.pdf")
- If vFile = False Then Exit Sub
- sPath = vFile
- vFile = Split(sPath, "")
- sPath = Left(sPath, Len(sPath) - Len(vFile(UBound(vFile))))
-
- sPDF = Dir(sPath & "*.pdf")
- ReDim vFile(1 To 1)
-
- Do While sPDF <> ""
- nI = nI + 1
- ReDim Preserve vFile(1 To nI)
- vFile(nI) = sPDF
- sPDF = Dir
- Loop
- If nI = 0 Then Exit Sub
-
- Set acroApp = CreateObject("AcroExch.App")
- Set acroAVDoc = CreateObject("AcroExch.AVDoc")
- For nI = 1 To UBound(vFile)
- If acroAVDoc.Open(sPath & vFile(nI), "文档转换") Then
- Set acroPDDoc = acroAVDoc.GetPDDoc()
- Set oJSO = acroPDDoc.GetJSObject
- oJSO.SaveAs sPath & "发票.jpg", "com.adobe.acrobat.jpeg"
- acroApp.CloseAllDocs
- PrintPic sPath & "发票.jpg"
- End If
- Next
- acroApp.Exit
- Set oJSO = Nothing
- Set acroPDDoc = Nothing
- Set acroAVDoc = Nothing
- Set acroApp = Nothing
- If Dir(sPath & "发票.jpg") <> "" Then Kill sPath & "发票.jpg"
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- MsgBox "打印结束!"
- End Sub
- Private Sub PrintPic(ByVal sPicFile As String)
- Dim oPicture As Object, nTop As Double, nLeft As Double
-
- With ActiveSheet
- nTop = .[A1].Top
- nLeft = .[A1].Left
- For Each oPicture In .Shapes
- If oPicture.Name <> "CommandButton1" Then oPicture.Delete
- Next oPicture
- Set oPicture = .Pictures.Insert(sPicFile)
- With oPicture
- .Name = "Invoice_IMG"
- .Top = nTop
- .Left = nLeft
- End With
- .PrintOut
- oPicture.Delete
- End With
- End Sub
复制代码
|
评分
-
4
查看全部评分
-
|