邮件合并 IF 字段和 VBA 出现问题
我有一个非常简单的邮件合并,它连接到 SQL Server 数据库
邮件合并有两个字段,一个是
{MERGEFIELD Dealer_Name}
另一个是下面的 IF 字段
{IF {MERGEFIELD Dealer_Name}="Joe" "1" "0"}
但是 IF 字段不执行。 Dealer_Name 合并字段确实执行并显示每个经销商名称或每个页面,但 IF 字段仅显示为 Dealer_Name}=
也可以编写 VBA 函数或过程,然后将其添加到单词邮件中将文档合并为字段或合并按钮或其他内容。
例如,假设我有以下 VBA 过程,
Public Sub PrintSomeText
Selection.TypeText("Hello World")
End Sub
我可以将其作为宏或其他内容添加到邮件合并文档中,以便它在放置到文档中的位置的每个页面上打印出“Hello World”吗?
I have a very simple mail merge that is connected to an SQL server database
The mail merge has two fields on it, one is
{MERGEFIELD Dealer_Name}
the other is the following IF field
{IF {MERGEFIELD Dealer_Name}="Joe" "1" "0"}
However the IF field does not execute. The Dealer_Name merge field does execute and displays each dealer name or each page but the IF field just displays as Dealer_Name}=
Also is it possible to write a VBA function or procedure and then add it to the word mail merge document as a field or merge button or something else.
For example let say I have the following VBA procedure
Public Sub PrintSomeText
Selection.TypeText("Hello World")
End Sub
Could I add this to the mail merge document as a macro or something so that it prints out "Hello World" on each page in the locate that it was placed onto the document?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够让 IF 字段代码工作,不知道如何工作,它刚刚开始工作。
我还发现您可以通过使用 DOCVARIABLE 或 REF 字段代码在 Word 邮件合并文档中使用 VBA 代码。
对于遇到此问题的其他人:
添加如下所示的文档变量:
或如下所示的书签引用:
然后在 VBA (Alt+F11) 中执行以下操作:
在项目中(项目名称),例如 Project(MailMergeDemo)
在“Microsoft Word 对象”下
双击“ThisDocument”
并输入以下代码
从下拉列表中选择应用程序对象,然后选择 app_MailMergeBeforeRecordMerge 事件并输入以下代码:
您将需要关闭并重新打开文档以挂钩应用程序对象。
请参阅 http://support.microsoft.com/kb/285333 了解更多信息。
I was able to get the IF field code working, not sure how, it just started working.
Also I found that you can use VBA code in Word mail merge documents by using the DOCVARIABLE or REF field codes.
For anyone else who has this problem:
Add a document variable like this:
or a bookmark reference like this:
Then in VBA (Alt+F11) do the following:
In Project (Project name), e.g. Project(MailMergeDemo)
Under "Microsoft Word Objects"
Double click "ThisDocument"
and enter the following code
Choose the app object from the drop down and then choose the app_MailMergeBeforeRecordMerge event and enter the following code:
You will need to close and reopen the document to hook the application object.
Please refer to http://support.microsoft.com/kb/285333 for more information.