Word 邮件合并记录计数返回 -1 [英] Word Mail Merge recordcount returns -1

查看:69
本文介绍了Word 邮件合并记录计数返回 -1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查看 Word 邮件合并文档的数据源.

I am trying to go through a data source for a word mail merged document.

我运行邮件合并数据源的代码如下所示:

My code to run through the mail merge data source looks like this:

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
lastDoc = ActiveDocument.MailMerge.DataSource.RecordCount

现在一切正常.我遍历数据源并做我需要做的事情.

Now everything works really well. I run through the data source and do what I need to do.

现在我做这个的用户,由于其他原因,使用小助手功能:邮件合并助手(它存在于Word 2010中)

Now the user that I am making this for are, due to other reasons, using the small helper function: Mail Merger Helper (it exists in Word 2010)

然而,当他们使用它时,我的 ActiveDocument.MailMerge.DataSource.RecordCount 返回 -1.这意味着它无法决定数据源中的记录数.我的假设是邮件合并助手没有正确设置数据源.

When they use this however, my ActiveDocument.MailMerge.DataSource.RecordCount returns -1. Which means that it can't decide the number of records in the datasource. My assumption is that the Mail Merger Helper doesn't set the datasource correctly.

但这阻止了我重复邮件合并(当他使用帮助程序时,他仍然可以激活通常的邮件合并功能,例如查看合并结果).

But that prevents me from iterating the mail merge (when he uses the helper, he can still activate the usual mail merge functions such as seeing the result of the merge).

怎么了?有没有替代迭代合并的方法,这样我就可以一一获取记录?

What is wrong? Is there an alternative to iterating the merge, so I can get the records one by one?

推荐答案

谢谢 bibadia,你引导我走上正轨.

Thank you bibadia, you lead me down the right track.

当您将 ActiveRecord 设置为 wdLastRecord 时.您可以从 ActiveRecord 中读取最后一个数据源.所以我只需要抓住它,然后再次将 ActiveRecord 设置为 wdFirstRecord.

When you set the ActiveRecord to wdLastRecord. You can read the last data source off of ActiveRecord. So I just needed to grab that, and then set ActiveRecord to wdFirstRecord again.

Dim count As Integer

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
count = ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord

这篇关于Word 邮件合并记录计数返回 -1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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