将Excel工作表打印为PDF文件 [英] Printing an excel worksheet as a PDF file

查看:179
本文介绍了将Excel工作表打印为PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个子例程来将Excel工作表打印为PDF文件。这可以在使用Office 365的计算机上运行,​​但是当我在具有Office 2003的笔记本电脑上运行该程序时不起作用。

我已经在BOTH机器上使用Microsoft Print To PDF手动成功打印了工作表。笔记本电脑创建文件,但它没有任何内容,无法打开。它的大小为零字节,但如果手动创建它是288KB。

任何人都有任何想法发生了什么?



我尝试过:



我写的代码如下;

私有Sub SaveWorksheetAsPDF(Title As String,Path As String)
Dim FileName As String =\ ResultsSheet&标题& .pdf
Dim totalFileName As String = Path& FileName
'将文档打印为PDF
oSheet.PrintOut(副本:= 1,预览:= False,ActivePrinter:=Microsoft Print To PDF,PrToFileName:= totalFileName,PrintToFile:= True)

End Sub

解决方案

我进一步调查并发现Microsoft Print To PDF打印机

不喜欢文件名中的逗号。

我需要更改我的代码,以便它不会创建逗号。标题是DateTimePicker的输出,并产生类似2016年10月26日星期三的输出。

不明白为什么它在我的桌面上工作而不是在笔记本电脑上,但至少我有办法前进。

I have written a sub routine to print an excel worksheet as a PDF file. This works on my computer using Office 365 but does not work when I run the program on a laptop which has Office 2003.
I have successfully printed the worksheet manually using "Microsoft Print To PDF" on BOTH machines. The laptop creates the file but it does not have any content and cannot be opened. It has a size of zero bytes but if created manually it is 288KB.
Anybody have any ideas what is going on?

What I have tried:

The code I have written is as follows;

Private Sub SaveWorksheetAsPDF(Title As String, Path As String)
        Dim FileName As String = "\ResultsSheet" & Title & ".pdf"
        Dim totalFileName As String = Path & FileName
        'Print the document to PDF
        oSheet.PrintOut(copies:=1, Preview:=False, ActivePrinter:="Microsoft Print To PDF", PrToFileName:=totalFileName, PrintToFile:=True)

    End Sub

解决方案

I have investigated further and have found that the "Microsoft Print To PDF" printer
does not like commas in the filename.
I need to change my code so that it does not create commas. Title is the output from a DateTimePicker and produces an output like "Wednesday, October 26, 2016".
Do not understand why it works on my desktop and not on the laptop but at least I have a way forward.


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

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