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
You may also need to set G:
as trusted location (I assume that's a network drive).