Run-time error '5922' - Mail Merge

dirtychinchilla

Board Regular
Joined
Jun 21, 2013
Messages
234
Morning all,

I am attempting to automate a mail merge in word, with the source being an excel spreadsheet. I've included my code below, but it always give me the error "Run-time error '5922': Word was unable to open the data source."

I think it may have something to do with the format being set incorrectly, but I'm really unsure. Also, I haven't yet managed to have it generate the dialogue from which you can choose the source within the excel document.

Any help you guys could give me would be much appreciated.

Code:
Sub MailMerge()

    Dim SourceDoc As String
    Dim SelectedItems(1) As String


    With Application.FileDialog(msoFileDialogFilePicker)
        .AllowMultiSelect = False
        If .Show <> 0 Then
            SelectedItems(1) = SourceDoc
        Else
            Exit Sub
        End If
    End With
    
    ActiveDocument.MailMerge.OpenDataSource Name:=SourceDoc, _
        ConfirmConversions:=True, ReadOnly:=False, LinkToSource:=True, _
        AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
        WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
        Format:=wdOpenFormatAuto, Connection:= _
        "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=H:\Jonathon Hunter Hill\Mail Merge\AirMaster V 0.9.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:" _
        , SQLStatement:="SELECT * FROM `MailMerge$`", SQLStatement1:="", SubType _
        :=wdMergeSubTypeAccess
        
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
In your SQL string you have references to both SourceDoc and H:\Jonathon Hunter Hill\Mail Merge\AirMaster V 0.9.xlsm. You should have one or the other; otherwise there's a risk of ambiguity and conflict.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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