将特定范围的单元格导出为PDF-VBA [英] Exporting Specific Range of Cells to PDF - VBA

查看:592
本文介绍了将特定范围的单元格导出为PDF-VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vba将Excel中的当前工作表保存为PDF并将其导出为PDF.该代码有效,但是要发布的PDF是整个工作表(其中包括几百行空白行和列,这些行和列超出了我的文字位置.在此链接

I am trying to save and export a current sheet in Excel as a PDF using vba. The code is working, however the PDF that is being published is the entire sheet (which includes a couple hundred blank rows and columns past where I have text. At this link 1, there is a tutorial on how to do this through the "Options" menu in the Save As window. I would like my code to do this for me, and select the range that encompasses only where I have text. This worksheet being exported is going to be used by many to create PDF's, with changes in the size of data in this worksheet. This explains my reasoning for wanting to do this through the code automatically as the file is exported. Any help would be great. Thanks!

推荐答案

设置打印区域, 这会将您的打印区域从A1设置为"D"列中的最后一个单元格

Set print area, This will set your print area from A1 to the last cell in Column "D"

Sub Set_PrintRnag()
    Dim LstRw As Long
    Dim Rng As Range
    LstRw = Cells(Rows.Count, "D").End(xlUp).Row
    Set Rng = Range("A1:D" & LstRw)
    ActiveSheet.PageSetup.PrintArea = Rng.Address

End Sub

这篇关于将特定范围的单元格导出为PDF-VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆