![]() |
|
#1
|
||||
|
||||
![]()
To be able to choose a datasource, your document need to be a 'normal' one, not a mailmerge one; otherwise the datasource is already chosen. Only after that can the rest of your code come into play. Accordingly, try:
Code:
Sub RunMailmerge() Dim sPath As String 'Kill off any previous datasource connections Application.DisplayAlerts = wdAlertsNone 'Let the user select a datasource With Application.Dialogs(wdDialogMailMergeOpenDataSource) If .Show = -1 Then sPath = .Name Else GoTo NoMerge End If End With If sPath = "" Then GoTo NoMerge 'Run the merge With ActiveDocument With .Mailmerge .MainDocumentType = wdFormLetters .OpenDataSource sPath .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=False 'Disconnect from the datasource .MainDocumentType = wdNotAMergeDocument End With .Saved = True End With NoMerge: Application.DisplayAlerts = wdAlertsAll End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#2
|
|||
|
|||
![]()
macropod,
I ran it and it lets me choose my datasource, but I want it to remain with the current word document that has all the merge fields set. The code you gave me opens up a new document with no merge fields. I need the merge fields to remain in my label because the users will not know how to set all this up. Do I change the .Destination = wdSendToNewDocument to something else? |
#3
|
||||
|
||||
![]() Quote:
Quote:
Quote:
.OpenDataSource sPath Working through the dialog already connects once, so there's no need to do it again. My bad. Quote:
Private Sub Document_Open()
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
![]()
I fixed the issue of it asking me twice to select my list.
I want the rest of the Macro to run automatically after I select my file. I need it to select "OLE DB Database File" and then always select the same list from the excel file say "My_List". Then have it finished ready to be able to select the Print options. Here is what comes up when I record the macro to do this, but where do I insert this into the code you provided me with? and what do I need to add/delete to make it function properly? Code:
SQLStatement:="SELECT * FROM `My_List`", SQLStatement1:="", SubType:= _ wdMergeSubTypeAccess |
![]() |
Tags |
mail merge, vbs |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
billybeach | Outlook | 2 | 04-27-2013 04:38 AM |
Mail Merge Code (Default Display) | ochiha_ita | Mail Merge | 3 | 04-22-2013 04:04 AM |
![]() |
tonywatsonmail | Mail Merge | 4 | 04-27-2012 01:57 AM |
Mail Merge saved to single .pdf | treetop | Mail Merge | 1 | 08-10-2011 03:28 PM |
Mail merge Field Code Manipulation | macjnr | Mail Merge | 0 | 09-10-2009 11:37 AM |