来自Access 2013的邮件合并,而不是Access 2000
有旧版访问权限的邮件合并文档:https://support.microsoft.com/en-us/kb/209976
但我无法找到2013版的任何文档或建议。
目的: 在MS Access中有一个按钮,根据所选数据触发邮件合并。
问题:
如果我手动执行邮件合并工作正常,并在合并之前导出我的数据。如果我尝试创建实时链接,它将失败。我的表是Office 365样式共享点列表 - 这看起来导致问题超时和锁定问题。所以我怀疑在合并之前我可能需要进行导出。
Access 2000样式邮件合并代码:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\Microsoft " & _
"Office\Office\Samples\Northwind.mdb", _
LinkToSource:=True, _
Connection:="TABLE Customers", _
SQLStatement:="SELECT * FROM [Customers]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
答案 0 :(得分:0)
导出为xls然后运行邮件合并。
Private Sub Command53_Click()
DoCmd.OutputTo acOutputQuery, "Mail Merge Query Name", acFormatXLS, "Temp export mail merge file.xls"
Set objWord = GetObject("path to Mail Merge file.docx", "Word.Document")
' objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="Temp export mail merge file.xls", _
ReadOnly:=True, _
SQLStatement:="SELECT * FROM [Mail Merge Query Name$]"
objWord.MailMerge.Execute
objWord.Application.ActiveDocument.SaveAs2 FileName:="TmpMergeOuput.docx"
objWord.Application.ActiveDocument.Close
objWord.Close SaveChanges:=wdDoNotSaveChanges
End Sub
注意: