从 VBA 运行和打印 Crystal Report

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5231715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:47:47  来源:igfitidea点击:

Run and Print Crystal Report from VBA

vbacrystal-reportsexcel-vbacrystal-reports-xiexcel

提问by Martin

I want to automate CR report printing from VB/VBA.

我想从 VB/VBA 自动打印 CR 报告。

I have Crystal Reports XI Developer installed and .rpt files (some requiring parameters) to run and send to a printer, without requiring any user intervention.

我安装了 Crystal Reports XI Developer 和 .rpt 文件(一些需要参数)来运行并发送到打印机,无需任何用户干预。

Now, I stuck at the very first step, adding the correct libraries. There are probably about 50 libraries or so that start with Crystal Reports or Business Objects, and I have no idea which ones I need.

现在,我坚持第一步,添加正确的库。大概有 50 个左右的库以 Crystal Reports 或 Business Objects 开头,我不知道我需要哪些。

Any pointers to get me started would be appreciated.

任何让我开始的指示将不胜感激。

Thanks Martin

谢谢马丁

回答by Martin

Ok, I solved my problem.

好的,我解决了我的问题。

CRAXDRT.dllaka Crystal Reports ActiveX Designer Run Time Libraryis the correct library.

CRAXDRT.dllaka Crystal Reports ActiveX Designer 运行时库是正确的库。

Here is some sample code:

下面是一些示例代码:

Dim CR As New CRAXDRT.Application
Dim rep As CRAXDRT.Report
Set rep = CR.OpenReport(Range("CRpath"))
rep.ParameterFields(1).AddCurrentValue "Boston"
rep.ParameterFields(2).AddCurrentValue "Cars"
rep.Database.Tables(1).ConnectionProperties("Password").Value = "pw12345"
rep.ReadRecords
rep.PrintOut promptUser:=False, numberOfCopy:=1 ' promptUser:=True doesn't work

回答by PowerUser

It depends on your budget, but I recommend a 3rd party program called Visual Cut (http://www.milletsoftware.com/Visual_CUT.htm). Using either a command line or the built-in GUI, you can process Crystal Report files pretty much any way you want, including PDFing, emailing, and even printing directly to a printer. So you can skip the VBA entirely if you want.

这取决于您的预算,但我建议使用名为 Visual Cut ( http://www.milletsoftware.com/Visual_CUT.htm)的 3rd 方程序。使用命令行或内置 GUI,您几乎可以以任何方式处理 Crystal Report 文件,包括 PDF 格式、电子邮件,甚至直接打印到打印机。因此,您可以根据需要完全跳过 VBA。

It's been around since 2002 and the developer has been continuously adding custom features to it by customer request, so it suffers a little from 'feature creep'. However, the manual (downloadable for free from the website) does a good job of keeping it all in perspective. Also, if you get the maintenance agreement, the developer is very responsive. In my case, he usually returns my calls within the day.

它自 2002 年以来一直存在,开发人员一直在根据客户的要求不断向其添加自定义功能,因此它受到了“功能蠕变”的影响。但是,该手册(可从网站免费下载)很好地使所有内容保持正确。此外,如果您获得维护协议,开发人员会非常敏感。就我而言,他通常会在一天内回复我的电话。

*(This isn't the developer talking, just a satisfied customer)

* (这不是开发人员在说话,只是一个满意的客户)