Thread: csv issue
View Single Post
 
Old 10-30-2014, 04:40 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Your use of 'Private Sub Document_New' indicates you're trying to run your mailmerge from a Word template, instead of a mailmerge main document. That is not how mailmerges are meant to be run; they're meant to be run from a document.

The code I posted assumed you were running you mailmerge from an application other than Word. With the following revision you can run it from a Word document:
Code:
Private Sub Document_Open()
' Demo code for a vba-driven mailmerge.
Application.DisplayAlerts = wdAlertsNone
Dim StrSrc As String
StrSrc = "H:\QL\ASBL001.csv"
With ActiveDocument
  With .MailMerge
    .MainDocumentType = wdFormLetters
    .OpenDataSource _
      Name:=StrSrc, ReadOnly:=True, AddToRecentFiles:=False, LinkToSource:=False, _
      Connection:="", SQLStatement:="", SQLStatement1:="", SubType:=wdMergeSubTypeOther
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    With .DataSource
      .FirstRecord = wdDefaultFirstRecord
      .LastRecord = wdDefaultLastRecord
    End With
    .Execute Pause:=False
    .MainDocumentType = wdNotAMergeDocument
  End With
  .Close False
End With
Application.DisplayAlerts = wdAlertsAll
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote