将所选区域打印为1页PDF

时间:2016-09-20 11:47:49

标签: vba pdf

继续下面的代码,如何将打印区域合并到一个页面?

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "c:\Book1.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True

2 个答案:

答案 0 :(得分:0)

一旦你出口,它就不再可能了。

我做的是,我是使用PageSetup更改.FitToPagesWide = 1导出前

 With ActiveSheet.PageSetup
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .Orientation = xlLandscape
End With

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="c:\Book1.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=True, _
OpenAfterPublish:=True

答案 1 :(得分:0)

这是一个更好的解决方案,它确保不要打印任何多余的注释,并且所选内容将以PDF格式打印在一页上。您还将收到一个对话框,询问您要保存到哪里,这将正常工作。关于整个代码,最妙的部分是查看它说pdf的地方,然后将格式更改为所需的格式,然后应保存为所需的格式:

Sub Macro1()
Dim file_name As Variant
file_name = Application.GetSaveAsFilename(FileFilter:="Adobe PDF File_ (*.pdf), *.pdf")
ActiveSheet.PageSetup.PrintComments = -4142

    Range("B2:X41").Select
    Selection.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:=file_name, Quality:=xlQualityStandard, _
        IncludeDocProperties:=False, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
    Range("A1").Select
End Sub