简体   繁体   中英

Mail Merge VBA - Access 2016 (Runtime Error 287)

Our company has recently undergone a big upgrade from office 2010 to 2016, and now we are having an issue with one of our VBA macros, shown below.

Function MergeIt()
Dim objWord As Word.Document
Dim SaveAsName As String
Dim Year As String
Dim DANo As String
Dim Revision As String
Dim strSource As String

Set objWord = GetObject("G:\Dev_&_Tech_Serv\Development\DAAssessTool\MailMerge1.dot", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
'Set the mail merge data source as the DAApproval Database.
objWord.MailMerge.OpenDataSource Name:="G:\Dev_&_Tech_Serv\Development\DAAssessTool" & "\DARevD.mdb", LinkToSource:=True, Connection:="QUERY qry_Mailmerge", SQLStatement:="Select * from [DAConCheckID]"
' Execute the mail merge.
objWord.MailMerge.Execute
' Close the original form document
objWord.Saved = True
objWord.Close (False)
End Function

The error is throwing at the first Set line - throwing a Runtime error 287 "Application defined or object defined error". I'm making the assumption that the previous developer is incorrectly defining the Word document, but I cant find anything online that shows a different method of defining, or how to fix this error.

I now turn to the vast knowledge of the Stack community for some inspiration on what is going wrong, and how to remedy it.

Thanks in advance.

Your best choice will be to convert these old .dot files to the newer .dotx format.

If this isn't feasible, try unblocking these old formats in Word Options / Trust Center / File Block Settings

see http://answers.microsoft.com/en-us/office/forum/office_2016-word/word-2016-cannot-open-documents-with-doc/bf12fa10-4e28-4a6b-99b2-d42c1aa8cb4b/

You may also need to set G: as trusted location (I assume that's a network drive).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM