Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-06-2014, 05:10 AM
macropod's Avatar
macropod macropod is offline Can't merge mail from Excel Windows 7 32bit Can't merge mail from Excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, those are the parts of the code that would need changing. For example:
Code:
Sub RunMerge()


Dim strWorkbookName As String, Rslt strWorkbookName = ThisWorkbook.FullName Dim wdapp As New Word.Application Dim wddoc As Word.Document Rslt = InputBox("Please choose a merge type:" & vbCr & _ "1. Letter merge" & vbCr & _ "2. Label merge" & vbCr & _ "3. Envelope merge") If Rslt = vbCancel Then Exit Sub Rslt = Trim(Rslt) If Not IsNumeric(Rslt) Then Exit Sub If (Rslt > 3) Or (Rslt < 1) Then Exit Sub With wdapp 'Disable alerts to prevent an SQL prompt .DisplayAlerts = wdAlertsNone 'Open the mailmerge main document Select Case Rslt Case 1 Set wddoc = .Documents.Open(ThisWorkbook.Path & "\Letter Mail Merge Main Document.docx") Case 2 Set wddoc = .Documents.Open(ThisWorkbook.Path & "\Label Mail Merge Main Document.docx") Case 3 Set wddoc = .Documents.Open(ThisWorkbook.Path & "\Envelope Mail Merge Main Document.docx") End Select With wddoc With .MailMerge 'Define the mailmerge type Select Case Rslt Case 1 .MainDocumentType = wdFormLetters Case 2 .MainDocumentType = wdMailingLabels Case 3 .MainDocumentType = wdEnvelopes End Select '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
Note the change in the naming of the mailmerge main documents, one for each type.

The $ on the end of 'Sheet1' is necessary to tell the SQL statement that its using a worksheet. If you want to use a worksheet named Address, use Address$.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


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 02:34 PM.


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