I have a setup with one Excel workbook and one Word document which creates a set of customer delivery notes. The data for the notes is in the Excel book, and the Word document uses Mail Merge to create a printable document from it. The process is controlled by a VBA macro on the Excel side, which starts Word, opens the Word document and then calls a VBA macro in the Word document, which does the actual Mail Merge job.
I have used this weekly for about a year, and it has worked perfectly fine. But all of a sudden last week, the Word macro started throwing error 4605! This now occurs consistently, and on both Windows machines where I run it.
Trying to find answers, I have learned that 4605 is a very common error, indicating just about any reason that a statement in a macro cannot be executed. In my case, the statement is MailMerge.OpenDataSource, and the reason given is "because a macro is running". See code below.
I don't believe there is anything wrong with the parameters to OpenDataSource, I have tried to alter them in various ways. It appears rather that the call as such is forbidden for some reason. I have also tried to introduce a delay before the offending call, in case there is some hidden macro that needs to complete first. And I have tried pausing the Excel macro right after calling the Word macro. But no luck.
Public Sub PopulatePrintExit(odbcFile As String, pdfFile As String)
On Error GoTo closeThis
With ThisDocument.MailMerge
.OpenDataSource Name:= _
odbcFile, ConfirmConversions:=False, _
ReadOnly:=True, LinkToSource:=True, AddToRecentFiles:=False, _
Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=OdbcFile;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Typ", _
SQLStatement:="SELECT * FROM `Fraktsedelsdata$` WHERE (`Aviseringsnr` IS NOT null And `Aviseringsnr` <> '')"
.Destination = wdSendToNewDocument
On Error GoTo closeAll
.Execute
End With
...