Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open("C:\Desktop\Matrice
publipostage.docx")
ActiveDocument.MailMerge.OpenDataSource Name:="C:\Desktop\Appli
v11complet.xlsm", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=
C:\Desktop\Appli v11complet.xlsm;Mode=Read;Extended
Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry
Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type5;Jet",
SQLStatement:="SELECT * FROM `Feuil1$`", SQLStatement1:="",
SubType:=wdMergeSubTypeAccess
ActiveDocument.FollowHyperlink WordDoc
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Avec cette synthaxe, il me demande un objet requit au niveau de la ligne
"Provider= ..."
Je vous remercie par avance si vous pouviez m'apporter de l'aide.
Un message de "Hervé" qui a été publié sur ce forum (MPFE)
si ça peut t'aider ?
===========================================
Hervé
En parlant de fusion, tu veux dire publipostage ? je n'est pas grande
connaissance de Word mais tu pourrais passer par l'intermédiaire d'un
document qui te servirait de base de données ? Regarde ceci, je l'ai posté
il y a quelques temps pour quelqu'un qui ne mas jamais dit si cela lui
convenait ??? La macro crée un tableau dans un nouveau document comme base
de données pour un publipostage et ensuite crée un document principal pour
le publipostage. Fait un test si cela te convient et adapte. La liaison DDE
est une liaison tardive.
Sub Publipostage()
Dim AppWord As Object
Dim I As Integer
Dim FE As Worksheet
Dim PlageTitre As Excel.Range
Set FE = Worksheets("Feuil1")
Set AppWord = CreateObject("Word.Application")
CreerListe AppWord, FE
With AppWord
.Documents.Add
With .Selection
.ParagraphFormat.Alignment = 1
With .Font
.Name = "Arial"
.Bold = True
.Size = 16
End With
.TypeText "Circulaire"
.TypeParagraph
.TypeParagraph
.ParagraphFormat.Alignment = 0
With .Font
.Name = "Times New Roman"
.Bold = False
.Size = 10
End With
End With
Set PlageTitre = FE.Range(FE.[A2], FE.[IV2].End(xlToLeft))
With .Documents(1)
With .MailMerge
.MainDocumentType = 3 'wdCatalog
.OpenDataSource Name:=ThisWorkbook.Path & "\ListeNoms.doc"
Set PlageTitre = FE.Range(FE.[B1], FE.[IV1].End(xlToLeft))
With .Fields
.Add AppWord.Selection.Range, PlageTitre(1)
AppWord.Selection.TypeText " "
.Add AppWord.Selection.Range, PlageTitre(2)
AppWord.Selection.TypeParagraph
.Add AppWord.Selection.Range, PlageTitre(3)
AppWord.Selection.TypeText " "
.Add AppWord.Selection.Range, PlageTitre(4)
AppWord.Selection.TypeParagraph
.Add AppWord.Selection.Range, PlageTitre(5)
AppWord.Selection.TypeText " "
.Add AppWord.Selection.Range, PlageTitre(6)
End With
End With
End With
With .Selection
.TypeParagraph
.TypeParagraph
.TypeText "Ici ton texte..."
End With
.Visible = True
End With
Set AppWord = Nothing
Set FE = Nothing
Set PlageTitre = Nothing
End Sub
Sub CreerListe(AppWord As Object, _
FE As Worksheet)
Dim Doc As Object
Dim TableWd As Object
Dim Ligne As Object
Dim CelWD As Object
Dim Plage As Excel.Range
Dim CelXL As Excel.Range
Dim I As Integer
Dim NbCol As Integer
Dim NbLgn As Integer
Set Plage = FE.Range(FE.[B1], FE.[B65536].End(xlUp))
On Error Resume Next
Kill ThisWorkbook.Path & "\ListeNoms.doc"
On Error GoTo 0
With Application.WorksheetFunction
NbCol = .CountIf(FE.Rows(1), "*")
NbLgn = .CountIf(FE.Columns(1), "*")
End With
With AppWord
Set Doc = .Documents.Add
With Doc
Set TableWd = .Tables.Add(.Range, NbLgn, NbCol - 1, 1, 1)
With TableWd
For Each CelXL In Plage
If CelXL <> "" Then
I = I + 1
.Cell(I, 1).Range.Text = Trim(CelXL.Text)
.Cell(I, 2).Range.Text = Trim(CelXL.Offset(0, 1).Text)
.Cell(I, 3).Range.Text = Trim(CelXL.Offset(0, 2).Text)
.Cell(I, 4).Range.Text = Trim(CelXL.Offset(0, 3).Text)
.Cell(I, 5).Range.Text = Trim(CelXL.Offset(0, 4).Text)
.Cell(I, 6).Range.Text = Trim(CelXL.Offset(0, 5).Text)
End If
Next CelXL
.Rows(1).Range.Bold = True
End With
.SaveAs ThisWorkbook.Path & "\ListeNoms.doc"
.Close
End With
End With
Set Doc = Nothing
Set TableWd = Nothing
Set Ligne = Nothing
Set CelWD = Nothing
Set Plage = Nothing
Set CelXL = Nothing
End Sub
===========================================
Une autre approche créée par Jiel,
Function Publipostage de Jièl Goubert
avec votre aide j'ai pondu ceci... ça marche parfaitement, il faut juste
penser à cocher "Word" dans les références
-------------------------------------------------------
Sub Publipostage()
Dim WdDoc As Word.Document
Dim Chemin, Fichier, Chemin_Fichier, Source As String
' Récupère le chemin des fichiers de la feuille "saisie"
' cellule "Chemin"
Chemin = Worksheets("Saisie").Range("Chemin")
' Récupère le nom du fichier de la feuille "saisie"
' cellule "Nom_Fichier"
' choisi dans une liste déroulante
Fichier = "\" + Worksheets("Saisie").Range("Nom_Fichier")
Chemin_Fichier = Chemin + Fichier
Source = "Procedure.xls" ' a modifier pour que ce soit variable
' Démarrer Word en ouvrant la lettre type
Set WdDoc = GetObject(Chemin_Fichier, "Word.Document")
With WdDoc
' Masque Word
.Application.Visible = False
' Créé la liaison à la base de données afin de pouvoir
' déplacer facilement les fichiers.
' Source contient le chemin d'accés au fichier
.MailMerge.OpenDataSource _
Name:=Source, _
LinkToSource:=True, _
Format:=wdOpenFormatAuto, _
SQLStatement:="SELECT * FROM `Données_Mailing$`"
' Lancer la fusion du 1er et seul enreg vers un nouveau doc
With .MailMerge
.Destination = wdSendToNewDocument
With .DataSource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=False
End With
' Affiche Word
.Application.Visible = True
' Ferme le doc ayant servi de modèle sans l'enregistrer
.Close (False)
End With
' Active Word
Application.ActivateMicrosoftApp xlMicrosoftWord
' Libère la mémoire
Set WdDoc = Nothing
End Sub
------------------------------------------
--
MichD
--------------------------------------------
"mister-mist" <miste...@domain-xyz.in> a écrit dans le message de groupe de discussion :
ev6dnYqT973...@giganews.com...
SuppressBlankLines = True
With .DataSource
FirstRecord = wdDefaultFirstRecord
LastRecord = wdDefaultLastRecord
End With