繁体   English   中英

Excel:导出到PDF不会更新

[英]Excel: Export to PDF not updating

我正在尝试让Excel将表格导出为PDF文件。 问题是,它总是导出具有相同数据的PDF。 是否添加更多条目或删除它们都没有关系。

这是我设法与初学者的VBA技能结合在一起的代码:

Sub export_pdf()

Dim area As String
area = Range("B3:H1048576").End(xlUp).SpecialCells(xlCellTypeConstants, 3).Address

With ActiveSheet.PageSetup
    .PrintTitleRows = "$3:$3"
End With

ActiveSheet.PageSetup.PrintArea = "" & area

With ActiveSheet.PageSetup
    .CenterHeader = "Käyttöpäiväkirja"
    .CenterFooter = "Sivu &P / &N"
    .LeftMargin = Application.InchesToPoints(0.590551181102362)
    .RightMargin = Application.InchesToPoints(0)
    .TopMargin = Application.InchesToPoints(0.748031496062992)
    .BottomMargin = Application.InchesToPoints(0.748031496062992)
    .HeaderMargin = Application.InchesToPoints(0.31496062992126)
    .FooterMargin = Application.InchesToPoints(0.31496062992126)
    .PrintHeadings = False
    .PrintGridlines = False
    .PrintComments = xlPrintNoComments
    .PrintQuality = 600
    .CenterHorizontally = False
    .CenterVertically = False
    .Orientation = xlPortrait
    .Draft = False
    .PaperSize = xlPaperA4
    .FirstPageNumber = xlAutomatic
    .Order = xlDownThenOver
    .BlackAndWhite = False
    .Zoom = 100
    .PrintErrors = xlPrintErrorsDisplayed
    .OddAndEvenPagesHeaderFooter = False
    .DifferentFirstPageHeaderFooter = False
    .ScaleWithDocHeaderFooter = True
    .AlignMarginsHeaderFooter = True
End With


ActiveSheet.ExportAsFixedFormat pbFixedFormatPDF, "käyttöpäiväkirja.pdf"

End Sub

有任何想法吗?

我已经尝试过您的代码,除了以下内容外,它看起来都不错:

ActiveSheet.ExportAsFixedFormat pbFixedFormatPDF, "käyttöpäiväkirja.pdf"

实际上,您需要提供文件的完整路径名以及.pdf扩展名。

我认为它应该类似于Drive:\\Folder\\SubFolder....\\Filename.pdf 如果要与其他用户共享,则始终可以使用使用FileSystemObject类的Windows Special Folder获取与用户无关的路径。

我强烈建议您让Excel确定数据的最后一行,而不是在H列中任意设置极高的长度。 我认为这样做可以使您的代码在运行时运行得更快:

Dim lastrow As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
End With
area = Range("B3:H" & lastrow).End(xlUp).SpecialCells(xlCellTypeConstants, 3).Address

暂无
暂无

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

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