从Excel VBA中设置适合可见的PDF格式

我正在尝试将excel工作表导出为pdf。 有什么办法,我可以设置PDF属性,以fit to visible使用VBA。 谢谢

以下是我正在使用的代码片段

 With wksSalesAndQuotaScoreCard '.PageSetup.LeftMargin=Application.InchesToPoints(0.7) .PageSetup.LeftMargin = Application.InchesToPoints(0.7) .PageSetup.RightMargin = Application.InchesToPoints(0.7) .PageSetup.TopMargin = Application.InchesToPoints(0.75) .PageSetup.BottomMargin = Application.InchesToPoints(0.75) .PageSetup.HeaderMargin = Application.InchesToPoints(0.3) .PageSetup.Orientation = xlLandscape .PageSetup.PrintTitleRows = "_SalesandQuotaScoreCardView" .PageSetup.CenterHorizontally = True .PageSetup.Order = xlDownThenOver .PageSetup.FitToPagesWide = 1 ''.PageSetup.Zoom = 50 Set rngSalesAndQuotaView = Range(.Shapes("_SalesandQuotaViewFrame").TopLeftCell.Offset(0, -1), .Shapes("_SalesandQuotaViewFrame").BottomRightCell.Offset(1, 0)) rngSalesAndQuotaView.Select End With wksScoreCardPayoutView.Select wksSalesAndQuotaScoreCard.Select False Selection.ExportAsFixedFormat xlTypePDF, IncludeDocProperties:=True, openafterpublish:=True wksCustomizeScoreCard.Activate 

Adobe在打开文档时可以使用一组代码:

http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

请注意,这些只适用于经过认可的Adobe Reader,并不是所有的PDF阅读器都能接受这些命令。

您可能必须让Adobe Acrobat 在Adobe帮助论坛上根据此答案手动设置条件:

关于OP:“我如何设置默认打开100%变焦放大倍率的所有PDF?”

使用Acrobat Pro,运行批处理(序列)/操作以运行“打开选项”序列。 此序列允许设置PDF文档属性的“初始视图”选项卡下所有项目的值。

关于PDF文档属性>初始视图:访问打开的PDF文档属性(Ctrl + D,Cmd + D)。 转到初始视图选项卡。 顶部窗格(布局和放大)允许configuration:

导航选项卡:仅页面| 书签面板和页面| 页面面板和页面| 附件面板和页面| 图层面板和页面布局:默认| 单页| 单页连续| 双向(面对)| 双向(封面)| 双向连续(封面)放大:默认| 实际尺寸| 适合页面| 适合宽度| 适合高度| 适合可见| 放大率(25%至6400%)

“默认”以外的configuration设置决定了如何在最初查看PDF。

初始视图中所有窗格中所有值的设置可以通过使用批次序列/操作(需要Acrobat Pro)为一个或多个PDFbuild立。

这种function在企业环境中使用,在LAN / WAN“电子图书馆”中部署大型文档集以向最终用户提供一致的初始视图。

它还为内容作者提供了一种机制,用于为其部署的内容(例如分布在光存储介质上的PDF文档集合)build立初始视图。

对于创build的PDF的典型默认“初始视图”:通过Acrobat创buildPDF时,PDF文档的默认“布局和放大”初始视图为: – | 导航:仅页面 – | 页面布局:默认 – | 放大:默认 – | 打开页面:1

关于Open Parameters文档 – 尽pipe本文提供了几个命令行选项,但文档的主要焦点是使用URL打开最初打开的URL的目标PDF。

值得注意的是,该文件是特定于url,不适用于UNC链接(与LAN / WAN链接)。

如果我理解了你的请求,你需要你的打印区域(因为出口到PDF就像打印)来调整宽度和高度。 你有.PageSetup.FitToPagesWide = 1语句,现在你也需要.FitToPagesTall = 1 ,所以你的代码将如下所示:

  With wksSalesAndQuotaScoreCard '.PageSetup.LeftMargin=Application.InchesToPoints(0.7) .PageSetup.LeftMargin = Application.InchesToPoints(0.7) .PageSetup.RightMargin = Application.InchesToPoints(0.7) .PageSetup.TopMargin = Application.InchesToPoints(0.75) .PageSetup.BottomMargin = Application.InchesToPoints(0.75) .PageSetup.HeaderMargin = Application.InchesToPoints(0.3) .PageSetup.Orientation = xlLandscape .PageSetup.PrintTitleRows = "_SalesandQuotaScoreCardView" .PageSetup.CenterHorizontally = True .PageSetup.Order = xlDownThenOver .PageSetup.FitToPagesWide = 1 .FitToPagesTall = 1 ''.PageSetup.Zoom = 50 Set rngSalesAndQuotaView = Range(.Shapes("_SalesandQuotaViewFrame").TopLeftCell.Offset(0, -1), .Shapes("_SalesandQuotaViewFrame").BottomRightCell.Offset(1, 0)) rngSalesAndQuotaView.Select End With 

如果这不是解决scheme,请解释什么是适合你的。

“缩放级别”不是PDF文件的文档属性,而是应用程序属性。 至多,我们可以做什么,直接从Excelmacros打开PDF文件,并使用“SendKeys”设置所需的缩放级别。

请参阅下面这段代码,它适用于我:

 Function PDFOpenFile(inPath As String, inPageNo As Long, inZoom As Variant) 'This function opens the PDF document with the specified 'Page number and zoom level 'The Page Number and Zoom Level are simulated through SendKeys method ' ************ Important ******************* ' When the macro runs, do not use the keyboard ' else the SenKeys may not function as desired ThisWorkbook.FollowHyperlink inPath, NewWindow:=True SendKeys ("^+N" & inPageNo & "~^" & inZoom), True End Function Sub MyDocument() ' After file name, the firt parameter is for page no, the second parameter is for zoom level PDFOpenFile "D:\MyFile.pdf", 3, 3 ' Zoom Level Details '0: Full Page '1: Zoom to 100% '2: Page Width '3: Fit visible '4: visible width / Reflow ' These zoom level are visible in acrobat reader. Go to "View > Zoom" and see the shortcut mentioned ' If the shortcuts are different for your case, you may modify the parameter passed as argument End Sub 

我使用PDFCreator打印了一张表单,其中“不缩放”和“在一页上打印”。 两者之间的差异是

 .Zoom = 100 

 .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 1 

我认为这将是“打印机”依赖。 当你简单地保存PDF时,你不会得到这些选项,但结果也不错。

 Range("A1:H34").Select Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\myfile.pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False 

我认为很大程度上取决于你如何创build你的PDF。

打印设置因计算机而异,因为只有默认打印机定义了“打印区域”。 这在Excel,Word等中是一样的

因此,除非将所有正在访问该文档的计算机都设置为相同的默认打印机,否则您将无法为所有计算机定义该计算机。

我认为这是作为打印区域设置,你需要先在Excel中设置,然后再导出到PDF。 首先在页面布局中或在上面的代码的“With”块中执行此操作,然后运行导出到PDF的代码。