简体   繁体   English

使用VBA错误将多个工作表Excel文件转换为PDF

[英]Converting multiple sheet Excel file to PDF using VBA error

I am currently trying to convert a multiple sheet excel file to a PDF using VBA using the following code: 我目前正在尝试使用VBA使用以下代码将多张Excel文件转换为PDF:

Private Sub CommandButton1_Click()

Dim mySheets As Variant, sh

mySheets = Array("Sheet1", "Sheet2", "Sheet3")
For Each sh In mySheets
    Sheets(sh).PageSetup.Orientation = xlLandscape
Next

Sheets(mySheets).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="S:\GasInc\Services\B&ITS\OpsEng\EngServ\_Station Design\Projects\Station Co-ops\Angela Lian" & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False

End Sub

It converts my file fine, however for what I have on sheet 2 it splits it up into multiple pages in the PDF because I guess it does not scale it to fit the page. 它可以很好地转换我的文件,但是对于我在工作表2上的文件,它会将其拆分为PDF中的多个页面,因为我想它无法缩放以适合页面。 I was wondering how I could modify the code to make it scale this sheet so it will fit on one page of the PDF. 我想知道如何修改代码以使其缩放此工作表,使其适合PDF的一页。

Thanks! 谢谢!

I have a similar sub in one of the tools I use. 我使用的一种工具中有一个类似的子项。 Do you have your worksheet's width / height scale to fit properties set to 1 page? 您是否将工作表的宽度/高度比例设置为1页以适合属性?

For Each sh In mySheets
    With Sheets(sh).PageSetup
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
Next sh

One of the weird things I've run into is scaling issues when converting to PDF with some chart / image objects. 我遇到的一件奇怪的事情是在将某些图表/图像对象转换为PDF时出现缩放问题。 For instance a logo looks fine on screen but prints stretched on the pdf. 例如,徽标在屏幕上看起来不错,但打印在pdf上。 I never fixed the problem, but through research it seemed due to the way the printer sees it compared to the screen resolution. 我从未解决过该问题,但经过研究,似乎是由于打印机查看它的方式与屏幕分辨率相比所致。 Have you ever run into that problem? 你遇到过这个问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM