将多张工作表保存为 .pdf [英] Save multiple sheets to .pdf

查看:39
本文介绍了将多张工作表保存为 .pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个报告电子表格,它从数据库中获取一些数据并形成三张汇总报告信息.我想从命令行自动运行电子表格,并让它自动将所有三个报告表保存为 PDF 文件.

I have a reporting spreadsheet that grabs some data from a database and forms three sheets of summary report information. I want to run the spreadsheet automatically from the command line, and have it automatically save all three reporting sheets as a PDF file(s).

起初我以为我可以在工作表上使用 VBA 宏通过一系列打印为 PDF"来完成此操作,但这需要一个中间交互式对话框来指定输出文件名.然后我发现我可以直接保存为pdf,宏可以设置输出文件名.然而,这会创建三个单独的文件,然后我必须在外部将它们放在一起以合并它们.

At first I thought I could have a VBA macro on the sheet do this by a series of "print as PDF", but that requires an intermediary interactive dialog box to specify the output file name. Then I find that I can just save as pdf, and the macro can set the output file name. However this creates three separate files, and I have to then later put them together externally to merge them.

(奇怪的是,另存为 pdf 只能保存一张工作表,而其他保存模式似乎可以保存整个工作簿.)

(It is odd that save as pdf only saves one sheet, where other save modes seem to save the entire workbook.)

是的,有一些工具可以稍后合并这三个文件,但我想知道是否有一些简单的方法可以让 Excel 将多个工作表一起保存为一个 pdf 文件.

Yes, there are tools for merging the three files later, but I want to know if there is some easy way to get Excel to save multiple sheets together as one pdf file.

我现在通过一系列的东西来打印:

I print now by a series of things like:

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, ...

我可以做一个类似(伪代码)的语句:

Could I do instead a single statement something like (pseudo-code):

ThisWorkbook.Sheets(1,2,3,4).ExportAsFixedFormat Type:=xlTypePDF, ...

推荐答案

首先选择要合并的工作表:

Start by selecting the sheets you want to combine:

ThisWorkbook.Sheets(Array("Sheet1", "Sheet2")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:	empo.pdf", Quality:= xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True

这篇关于将多张工作表保存为 .pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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