VBA - 通过访问进行邮件合并

发布于 2024-08-23 07:09:41 字数 804 浏览 2 评论 0原文

我不确定为什么我的代码不起作用.. 我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛溺水了 2024-08-30 07:09:42

你有Word Library的参考吗(代码窗口->工具->参考)?如果没有,您将需要使用内置常量的值,例如 wdOpenFormatAuto

编辑重新注释

由于您有一个文本文件,我不认为您的类型是正确的。尝试类似的方法:

''To create output, if required
''DoCmd.TransferText acExportDelim, , "qryMailMerge", strExportFullyQualifiedName, True

 With objWordDoc
     .MailMerge.OpenDataSource _
      Name:=strExportFullyQualifiedName, Format:=wdOpenFormatText
     .MailMerge.Destination = wdSendToNewDocument
     .MailMerge.MainDocumentType = wdDirectory
     .MailMerge.SuppressBlankLines = True
 End With

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:

''To create output, if required
''DoCmd.TransferText acExportDelim, , "qryMailMerge", strExportFullyQualifiedName, True

 With objWordDoc
     .MailMerge.OpenDataSource _
      Name:=strExportFullyQualifiedName, Format:=wdOpenFormatText
     .MailMerge.Destination = wdSendToNewDocument
     .MailMerge.MainDocumentType = wdDirectory
     .MailMerge.SuppressBlankLines = True
 End With
后来的我们 2024-08-30 07:09:42
  1. 您说过两次 strExportFullyQualifiedName 是文本文件的位置。我以前从未自动化过此过程,但我认为您只能从 Word 文件导出。

  2. strExportFullyQualifiedName 是否包含文件路径和文件路径?文件名?例如“C:\Test.Doc”?

  1. 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.

  2. Does strExportFullyQualifiedName contain both the filepath & filename? e.g. "C:\Test.Doc"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文