将报告输出为PDF格式以保存或作为电子邮件发送 [英] Output a report to PDF format to save or send as email

查看:89
本文介绍了将报告输出为PDF格式以保存或作为电子邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Access 2000数据库中的宏转换为VBA代码以便在Access 2007中使用。宏打开报告,格式化为使用print命令转到Adobe PDF打印机。转换后的宏VBA代码仅在普通视图中打开报表,用户必须转到Office按钮并将文件另存为PDF文件。原始宏为连续45个报告自动执行此过程。我需要修改或添加到新的VBA代码,以便通过将文件输出为PDF格式(无需打开文件)自动执行此过程,并提示用户输入保存PDF文件的位置。我需要帮助编写VBA代码以自动输出报告,以便所有用户必须响应的是提示文件位置以保存PDF文件(与以前一样使用宏)。以下代码是从宏到VBA的转换过程 -


DoCmd.OpenReport" rptmyreport",acViewNormal," ,


报告(每个报告)打开,用户必须转到Office按钮,另存为PDF,指定位置,然后关闭报告。对于有人一次为45个报告执行此过程,这是压倒性的。


我认为我有部分输出到PDF文件所需的代码;见下文 -


DoCmd.OutputTo acReport,rptmyreport,acFormatPDF," "," False"


这是正确的,这是我需要的唯一代码行吗?我正在使用Access 2007与Office SP2。我只是通过示例学习VBA,我将非常感谢对教程网站的任何帮助或指导。谢谢。


Carol

I am in the process of converting macros in Access 2000 databases to VBA code for use in Access 2007. The macros open reports which are formatted to go to the Adobe PDF printer using the print command. The converted macro VBA code only opens the report in normal view and the user has to go to the Office Button and save the file as a PDF file. The original macro automated this process for 45 consecutive reports. I need to modify or add to the new VBA code so that it automates this process by outputing the file to PDF format (without opening the file) and prompts the user for the location to save the PDF file. I need assistance in writing the VBA code to automate the output of the reports so that all the user has to respond to is a prompt for the file location to save the PDF file (as before with the macro). The following code is from the macro to VBA conversion process -

DoCmd.OpenReport "rptmyreport", acViewNormal, " ", " "

The report (each report) opens and the user has to go to the Office button, Save As PDF, specify the location, then close the report. This is overwhelming for someone do this process for 45 reports at a time.

I think I have part of the code necessary to output to a PDF file; see below -

DoCmd.OutputTo acReport, "rptmyreport", acFormatPDF, " ", "False"

Is this correct and is this the only line of code that I need? I am using Access 2007 with the Office SP2. I am just learning VBA, mostly by example, and I would appreciate any help or guidance to a tutorial site. Thank you.

Carol

推荐答案

你要求的是可能的,实际上并不太复杂。这是我在几个项目中实施的。给我一点时间,我会为你挖掘代码。


Pat
What you are asking for is possible, and actually not too complicated. It''s something that I''ve implemented in a couple of my projects. Give me a little time and I''ll dig the code up for you.

Pat


执行此操作的基本代码是

The basic code to do this is

展开 | 选择 | Wrap | 行号


感谢Pat,代码。我认为这正是我所寻找的。我对If ... Else语句有疑问。 If..Else语句是否确定文件对话框是否显示,是否只需要说明一次?


我将尝试为DoCmd编写循环;但是,由于我还是新手,我可以采取重复但简单的方法,为每个报告编写DoCmd语句。是否有可以帮助我的在线教程或良好的VBA for Access参考?你得到了很大的帮助。再次感谢。


Carol
Thank you, Pat, for the code. I think this is just what I was looking for. I do have a question about the If...Else statement. Does the If..Else statement determine whether or not the file dialog box displays and also does it only have to be stated once?

I will try to write the loop for the DoCmd; however, since I am still new to this I may take the repetitive but easy way out and write the DoCmd statement for each report. Is there an online tutorial or good VBA for Access reference you can recommend that could assist me? You''ve been a tremendous help. Thanks again.

Carol


这篇关于将报告输出为PDF格式以保存或作为电子邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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