在没有空白页的情况下转换PDF格式的工作簿

问题描述 投票:0回答:1

我编写了一个代码,用于将工作表从一个工作簿导出到另一个工作簿,然后将其转换为pdf,但我有很多空白页面(可能是因为隐藏的公式或我不知道。

如果你有任何想法添加到我的代码中以获得一个体面的文件,将非常感激。

 Workbooks.Open FileName:="C:\Users\User\Documents\Tests Salome\dailypdf.xlsx"

 Dim wbto2 As Workbook: Set wbto2 = Workbooks("dailypdf.xlsx")
 wb.Activate
For Each sht In Sheets
   If sht.Name <> "USD" And sht.Name <> "Balance" Then
      Else
     sht.Copy Before:=wbto2.Sheets(wbto2.Sheets.Count)
     Rows("140:351").EntireRow.Delete '(I tried to delete the hidden rows)

   End If
 Debug.Print sht.Name
Next

wbto2.Activate
Application.DisplayAlerts = False
Sheets("Sheet1").Delete
Application.DisplayAlerts = True


            FileName = Create_PDF(Source:=wbto2, _
                                      FixedFilePathName:=iFile, _
                                      OverwriteIfFileExist:=True, _
                                      OpenPDFAfterPublish:=False)

代码功能但由于空白页面的结果不满足我。

excel vba excel-vba pdf worksheet
1个回答
0
投票

你可以尝试下面的任何选项

1.在保存为PDF之前删除所有不需要的行。

2.设置打印区域

3.直接将excel范围保存为PDF

    'Enter Worksheet name, range Address, PDF file path and name
    Sheets("Sheet Name").Range("A1:D50").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Temp\PDF_name.pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
© www.soinside.com 2019 - 2024. All rights reserved.