将现有宏更改为打印到PDF

时间:2016-12-14 17:36:28

标签: excel vba pdf macros

我是VBA的新手,不知道如何完成我想要的任务。

有人可以告诉我如何将下面的宏打印设为PDF而不是默认打印机吗?

Sub PRINTMULTIPACKS()
'
' PRINTMULTIPACKS Macro
'

'
ActiveSheet.Unprotect
ActiveSheet.Range("$C$13:$D$22").AutoFilter Field:=1, Criteria1:="<>"
Sheets("EXPORT TO VENDOR MULTIPLE AREAS").Select
ActiveSheet.Unprotect
ActiveSheet.Range("$A$11:$AD$261").AutoFilter Field:=3, Criteria1:="<>"
Sheets("FIXTURE SCHEDULE").Select
ActiveSheet.Unprotect
ActiveSheet.Range("$A$4:$S$874").AutoFilter Field:=17, Criteria1:="<>"

Sheets("COVER MULTIPLE AREAS").Select
Range("D10").Select
Sheets(Array("COVER MULTIPLE AREAS", "EXPORT TO VENDOR MULTIPLE AREAS")).Select
Sheets("COVER MULTIPLE AREAS").Activate
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
Sheets("FIXTURE SCHEDULE").Select
ActiveSheet.Range("$A$4:$S$874").AutoFilter Field:=17
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFiltering:=True

Sheets("EXPORT TO VENDOR MULTIPLE AREAS").Select
ActiveSheet.Range("$A$11:$AD$261").AutoFilter Field:=3
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFiltering:=True
Sheets("COVER MULTIPLE AREAS").Select
ActiveSheet.Range("$C$13:$D$22").AutoFilter Field:=1
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowFiltering:=True
Range("C10").Select

End Sub

1 个答案:

答案 0 :(得分:0)

您可以保存为PDF,具体取决于您使用的Excel版本。

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users\sample\Documents\mySheet.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

其中C:\Users..是您要保存的路径和文件名。