Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2014, 03:52 AM
Mahmed1 Mahmed1 is offline Can't merge mail from Excel Windows 7 64bit Can't merge mail from Excel Office 2010 32bit
Novice
Can't merge mail from Excel
 
Join Date: Apr 2014
Posts: 17
Mahmed1 is on a distinguished road
Default

Hi Thank You



Im aware that the document to open and main document type will have to change. i wernt sure if the syntax for each type was different so my question is do i only have to change the highlighted parts to suit?

Would that be the only change or are the syntaxes or code need adding if i change from letter to envelope to label etc.

And can i add 1 line of code to tick the Dont add space between paragraphs

Code:
Sub RunMerge()
    Dim strWorkbookName As String
    strWorkbookName = ThisWorkbook.FullName
    Dim wdapp As Word.Application
    Set wdapp = New Word.Application
    Dim wddoc As Word.Document
    With wdapp
        'Disable alerts to prevent an SQL prompt
        .DisplayAlerts = wdAlertsNone
        'Open the mailmerge main document
        Set wddoc = .Documents.Open(ThisWorkbook.Path & "\Mail Merge Main Document.docx", _
    ConfirmConversions:=False, ReadOnly:=True, AddToRecentfiles:=False)
        With wddoc
            With .MailMerge
                'Define the mailmerge type
                .MainDocumentType = wdFormLetters
                'Connect to the data source
                .OpenDataSource Name:=strWorkbookName, ReadOnly:=True, _
                  AddToRecentFiles:=False, LinkToSource:=False, _
                  Connection:="Provider=Microsoft.ACE.OLEDB.12.0;" & _
                  "User ID=Admin;Data Source=strWorkbookName;" & _
                  "Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _
                  SQLStatement:="SELECT * FROM `Sheet1$`", _
                  SubType:=wdMergeSubTypeAccess
                .SuppressBlankLines = True
                With .DataSource
                    .FirstRecord = wdDefaultFirstRecord
                    .LastRecord = wdDefaultLastRecord
                End With
                'Define the output
                .Destination = wdSendToNewDocument
                'Excecute the merge
                .Execute
                'Disconnect from the data source
                .MainDocumentType = wdNotAMergeDocument
            End With
            'Close the mailmerge main document
            .Close False
        End With
        'Restore the Word alerts
        .DisplayAlerts = wdAlertsAll
        'Print the output document
        .ActiveDocument.PrintOut
        'Display Word and the document
        .Visible = True
    End With
End Sub
Reply With Quote
  #2  
Old 04-06-2014, 04:46 AM
Mahmed1 Mahmed1 is offline Can't merge mail from Excel Windows 7 64bit Can't merge mail from Excel Office 2010 32bit
Novice
Can't merge mail from Excel
 
Join Date: Apr 2014
Posts: 17
Mahmed1 is on a distinguished road
Default

Thank you sir

Would you recommend to use 3 different macros for each type
or
Change the file to open and main document based on selection

and what does the sheet$ do? $ And normally the SELECT statements requires '
I did not realise that with mail merge that's not actually a '.
*SubType:=wdMergeSubTypeAccess? I guess the linked source to false does not prompt me with that message box ?

1 last bit before I completely move away from mail merge :-) what bit of code can I have to Tick the line after paragraph?

How did you know which provider to use for sql ? Is this based on experience?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't merge mail from Excel mail merge in excel to send pdf forms heyullama Excel 7 12-01-2013 03:32 PM
Excel Mail merge Joren Word 0 07-09-2013 07:38 AM
Can't merge mail from Excel mail merge with excel and words don0712 Mail Merge 1 01-29-2013 06:53 PM
Can't merge mail from Excel Templates, pictures, Mail Merge and Excel kckay Word VBA 1 05-17-2012 08:51 PM
Can't merge mail from Excel Mail Merge from Excel Kieroncsmith Mail Merge 2 02-16-2012 10:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft