View Single Post
 
Old 09-24-2018, 08:06 PM
stevenel stevenel is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Jul 2018
Posts: 26
stevenel is on a distinguished road
Default

My current Excel and word template exceed the maximum size for upload. Thank you for your help !

Have you ever this ?
On other site I found this :

The solution is to create the data source file as a Word document instead of as a text file :
Code:
Dim dsDoc As Object
Set dsDoc = wwApp.Documents.Add
With dsDoc
     .Content.InsertAfter Text:=<merge field names text> & vbCr
     .Content.InsertAfter Text:=<merge field data text> ' no trailing vbCR
     .SaveAs sMergeFile
     .Close SaveChanges:=wdDoNotSaveChanges
End With
Set dsDoc = Nothing
I am just a little bit confuse how integrated in my code :

Code:
Dim strWorkbookName As String
    strWorkbookName = nomfichiermerge
    Dim wdapp As 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("C:\Document\Options - 002.docx")
        With wddoc
             .ActiveWindow.View.Type = wdNormalView
            With .MailMerge
                'Define the mailmerge type
                .MainDocumentType = wdDirectory
                'Connect to the data source
                .OpenDataSource Name:=strWorkbookName, ReadOnly:=True, AddToRecentFiles:=False, _
                Revert:=False, Format:=wdOpenFormatAuto, Connection:="Data Source=" _
                & strWorkbookName & ";Mode=Read", SQLStatement:="SELECT * FROM 'Sheet1'"
                .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
        'Display Word and the document
        .Visible = True
    End With
Reply With Quote