Search code examples
excelvbams-wordmailmerge

How to prevent "mail merge" warning to appear when opening an OLEObject word document from inside an Excel File


I've created an excel workbook that contain two word letter and created a VBA script that automatically mail-merge said letter using data inside the workbook itself.

However when i open the letters using "OLEObject.Activate" I encounter two problems :

  1. The document systematically show a "mail-merge" warning
  2. Said warning is systematically put in background forcing you to do an "Alt+Tab" to find it.

I've tried two methods to open the document :

Dim WDApp As Word.Application
Dim WDDoc As Word.Document

WDObject.Activate

Set WDApp = GetObject(, "Word.Application")
WDAPP.Visible = True
WDApp.DisplayAlerts = wdAlertsNone
Set WDDoc = WDApp.ActiveDocument

and :

Dim WDApp,WDOpen As Word.Application
Dim WDDoc As Word.Document

'for some reason if I try to create the application directly with WDApp it then won't be able to recognize the active document so I have to open word using a proxy
Set WDOpen = CreateObject("Word.Application")
WDOpen.Visible = True
WDOpen.DisplayAlerts = wdAlertsNone

Set WDApp = GetObject(, "Word.Application")

WDObject.Activate

Set WDDoc = WDApp.ActiveDocument

Solution

  • The simple answer is to not embed mailmerge main documents in your workbook. Save them outside Excel as ordinary documents before embedding them. This also means your VBA code will need to include the relevant SQL query code.