VBA - 通过访问进行邮件合并
我不确定为什么我的代码不起作用.. 我在 Access 03 中有 vba 代码,它打开一个运行邮件合并过程的 Word 文档。 当代码运行时,它会询问我标题分隔符是什么。我在导出文件中将它们指定为字段分隔符的逗号和记录分隔符。在我在word中确认这一点后,我收到运行时错误。
我收到的错误是: 运行时错误“5922”: Word 无法打开数据源。
strExportFullyQualifiedName 是一个文本文件,导出时其中列出了用作数据源文件的字段名称。
我检查了链接并验证,一切都存在。尚未建立连接。 strExportFullyQualifiedName 是 txt 文件的位置。
With objWordDoc
.MailMerge.OpenDataSource _
Name:=strExportFullyQualifiedName, Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, SubType:=wdMergeSubTypeAccess, AddToRecentFiles:=False
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.MainDocumentType = wdDirectory
.MailMerge.SuppressBlankLines = True
End With
谢谢 !
I'm not sure why my code is not working..
I have code in vba in Access 03 which opens a word document which runs a mail merge process.
When the code runs, it asks me what the Header Delimiters are. I specified those in the export file as a comma for a field delimiter and as the record delimiter. After I confirm this in word, I get a a run time error.
The error I'm getting is:
Run-time error '5922':
Word was unable to open the data source.
strExportFullyQualifiedName is a text file which is exported with the field names listed in there which is being used as a data source file.
I checked the links and verify, everything exists. The connection is not being made.
strExportFullyQualifiedName is the location of the txt file.
With objWordDoc
.MailMerge.OpenDataSource _
Name:=strExportFullyQualifiedName, Format:=wdOpenFormatAuto, _
ConfirmConversions:=False, ReadOnly:=False, SubType:=wdMergeSubTypeAccess, AddToRecentFiles:=False
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.MainDocumentType = wdDirectory
.MailMerge.SuppressBlankLines = True
End With
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有Word Library的参考吗(代码窗口->工具->参考)?如果没有,您将需要使用内置常量的值,例如 wdOpenFormatAuto
编辑重新注释
由于您有一个文本文件,我不认为您的类型是正确的。尝试类似的方法:
Do you have a reference to the Word Library (Code Window->Tools->References)? If not, you will need to use the values for built-in constants such as wdOpenFormatAuto
EDIT re Comment
As you have a text file, I do not believe that your types are correct. Try something like:
您说过两次 strExportFullyQualifiedName 是文本文件的位置。我以前从未自动化过此过程,但我认为您只能从 Word 文件导出。
strExportFullyQualifiedName 是否包含文件路径和文件路径?文件名?例如“C:\Test.Doc”?
You said twice that strExportFullyQualifiedName is the location of a text file. I've never automated this process before, but I thought you could only export from a Word file.
Does strExportFullyQualifiedName contain both the filepath & filename? e.g. "C:\Test.Doc"?