VBA Mail Merge - Stopped working today after 14 years

adamolivier

New Member
Joined
Nov 18, 2015
Messages
15
I have been using this VBA process for 14 years with little to no adjustment, and today I tried using it on a new computer and it is getting stuck. It will open Word, but stops there and stays blank. No errors or bug alerts. What can I try to fix it? Is there a setting in Word or Excel that I need to adjust?

Sub RunDeed_OM_Texas_Merge()

Dim wd As Object
Dim wdocSource As Object

Dim strWorkbookName As String

On Error Resume Next
Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
End If
Set wdocSource = wd.Documents.Open("C:\Document Generator")

strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name

wdocSource.MailMerge.MainDocumentType = wdFormLetters

wdocSource.MailMerge.OpenDataSource _
Name:=strWorkbookName, _
AddToRecentFiles:=False, _
Revert:=False, _
Format:=wdOpenFormatAuto, _
Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _
SQLStatement:="SELECT * FROM `Data$`"

With wdocSource.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

wd.Visible = True
wdocSource.Close SaveChanges:=False

Set wdocSource = Nothing
Set wd = Nothing

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Your code has the line:
Set wdocSource = wd.Documents.Open("C:\Document Generator")
but 'Document Generator' doesn't look like a valid filename. One would expect it to be 'Document Generator.doc' or 'Document Generator.docx'.
You are right, I mentioned that I fixed that above. Thanks for looking at it though.
 
Upvote 0
Hello, maybe the MS Access is not setted up correctly on this PC. I believe the SQL query is ran by some dependencies of Access. Did you try to repair MS Office, or check if Access is installed?

(A similar issue Redirecting )
 
Upvote 0
After some testing and moving of files, the issue appears to be that it only works when the Excel file is saved on a PC hard drive or server. When it is saved to a OneDrive or SharePoint folder that is synced with a desktop, the merge doesn't work. Any ideas on what could be going on?
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top