سؤال

My scenario is similar to that described in excel VBA to Automatically select Yes when prompted during mail merge, except that I am running the VBA from the Access database that contains the data to be merged, and (this may be relevant) the Merge is using a DDE data connection because the Query is a complex one and is not visible in by ODBC. I am trying to run a Word mail merge from an Access Run-Time Application which will be used by people who are not very computer-literate, so I want to avoid confusing them with unnecessary dialogs. The Answer to the previous question does, indeed, work for me, by preventing the prompt to allow the query to be opened, and everything else happens as it should, but the Merge returns a "no data source" error when the procedure hits the .Execute line. It appears that the query prompt is indeed suppressed, but the query is not opened.

' open the mail merge layout file
objWord.Visible = True ' for now
lngAlerts = objWord.DisplayAlerts
objWord.DisplayAlerts = False
objWord.Documents.Add strInFileName
objWord.DisplayAlerts = lngAlerts

With objWord.ActiveDocument.MailMerge
    .MainDocumentType = 0 ' wdFormLetters
    .Destination = 0 ' wdSendToNewDocument
    .SuppressBlankLines = True
    .Execute Pause:=False
End With

Can anyone shed any light on this?

هل كانت مفيدة؟

المحلول

When the dialog is bypassed, it is as if the user had pressed the No button. See Microsoft's KB article at: http://support.microsoft.com/kb/825765

i.e. your code will probably need to issue an OpenDataSource call before anything else, unless you can set the registry value described in the article.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top