Data Source in new instance of Excel MailMerge

VBA_READY

New Member
Joined
Dec 10, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Is there a way for me to perform a mail merge and use a data source that is will be opened in a new instance of Excel? Currently I modified some code to work for me, but the VBA opens the workbook in one instance, then when the code for mail merge occurs, it opens a second instance of the same workbook name. I have a progress bar that tells how far along the code is running and the screen keeps flickering even with everything turned off.

VBA Code:
 myPath = ThisWorkbook.Path & "\signdata\"
    arrayCount = CountFilesInFolder(myPath)
    Debug.Print arrayCount
    
    'Target File Extension (must include wildcard "*")
    myExtension = "*.xlsx*"
    
    'Target Path with Ending Extention
    myFile = Dir(myPath & myExtension)

    
    
    counter = 0
    'Loop through each Excel file in folder
    
    Do While myFile <> ""
        'Set variable equal to opened workbook
        
        Set wb = app.Workbooks.Open(Filename:=myPath & myFile)
            strWorkbookName = wb.Path & "\" & myFile
            app.Visible = True
         'Set newSheet = wb.Worksheets(1)
            
        rowCount = wb.Sheets("Sheet1").Cells(Rows.count, 1).End(xlUp).Row
        
        'Ensure Workbook has opened before moving on to next line of code
        DoEvents
        
        
        'Get next file name
        myFile = Dir
        'Start of mailmerge
        wd.Visible = True
        Set wdocSource = wd.Documents.Open(SavePath & "\Template\Closeout_Signs_TEMPLATE.doc")
        wdocSource.MailMerge.MainDocumentType = wdFormLetters
        wdocSource.MailMerge.OpenDataSource _
                            Name:=strWorkbookName, _
                            AddToRecentFiles:=False, _
                            Revert:=False, _
                            Connection:="Data Source=" & strWorkbookName  & ";Mode=Read", _
                            SQLStatement:="SELECT * FROM `Sheet1$`"
                            Debug.Print Name
                            Debug.Print Connection
        
        With wdocSource.MailMerge
            .Destination = wdSendToNewDocument
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = 3
                .LastRecord = rowCount
            End With
            .Execute Pause:=False
        End With
        
        On Error Resume Next
        wd.ActiveDocument.FitToPages
        
        Dim PathToSave As String
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Watch MrExcel Video

Forum statistics

Threads
1,127,321
Messages
5,624,003
Members
416,004
Latest member
reitz1

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
Top