![]() |
|
#1
|
||||
|
||||
![]() Try something based on: Code:
Sub Demo() Dim strWkBkNm As String With Application .DisplayAlerts = wdAlertsNone 'Select a data source With .FileDialog(FileDialogType:=msoFileDialogFilePicker) .AllowMultiSelect = False .Filters.Add "Excel Files", "*.xls*", 1 If .Show = True Then strWkBkNm = .SelectedItems(1) Else Exit Sub End If End With With .ActiveDocument With .MailMerge 'Disconnect from the data source .MainDocumentType = wdNotAMergeDocument 'Define the mailmerge type .MainDocumentType = wdFormLetters 'Suppress Blank Lines .SuppressBlankLines = True 'Define the output .Destination = wdSendToNewDocument 'Connect to the data source, Applying the required SQL Statement, 'including filters, on the 'SQLStatement' line and the ''SQLStatement1' line, for SQL Statements over 255 characters .OpenDataSource Name:=strWkBkNm, ReadOnly:=True, _ AddToRecentFiles:=False, LinkToSource:=False, _ Connection:="Provider=Microsoft.ACE.OLEDB.12.0;" & _ "User ID=Admin;Data Source=StrWkBkNm;" & _ "Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _ SQLStatement:="SELECT * FROM `Blad1$`", _ SQLStatement1:="", SubType:=wdMergeSubTypeAccess With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=False 'Disconnect from the data source .MainDocumentType = wdNotAMergeDocument End With End With .DisplayAlerts = wdAlertsAll End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Get the latest filename from directory with a macro | spider85 | Word VBA | 2 | 07-10-2017 10:43 PM |
![]() |
Gwinnett | Mail Merge | 3 | 03-01-2017 09:25 AM |
![]() |
JON25T | Mail Merge | 3 | 12-22-2016 01:34 PM |
![]() |
staicumihai | Word VBA | 2 | 10-28-2016 03:01 AM |
![]() |
jc491 | Word VBA | 8 | 09-11-2015 08:31 AM |