Bonjour =E0 tous,
J'ai cr=E9e une macro qui a pour but de pr=E9parer dans excel=20
une source de donn=E9es pour =E9tablir une fusiion dans word.
A priori l'ex=E9cution manuelle se passe correctement mais=20
quand je lance la macro, des messages d'erreur suivant=20
apparaissent :
Dans excel : "excel attend la fin de l'execution OLE d'une=20
autre application "
dans word : "op=E9ration plus longue que pr=E9vu, attendre ?"
Bref, la macro ne s'execute pas.
voici le code de ma macro
Sub Macro9()
'
' Macro9 Macro
' '
MyAppID =3D Shell("C:\Program Files\Microsoft=20
Office\Office\Winword.EXE=20
C:\Base_test\xxx\xxxx\traitements\R=E9ferentiel_word\DCT.doc"
, 1)
ActiveDocument.MailMerge.MainDocumentType =3D=20
wdFormLetters
Documents.Add DocumentType:=3DwdNewBlankDocument
ActiveDocument.MailMerge.OpenDataSource Name:=3D _
"C:\base_test_gp2
\daniel\phsa\Traitements_opcvm\Tables\table_extraction_word
.xls" _
, ConfirmConversions:=3DFalse, ReadOnly:=3DFalse,=20
LinkToSource:=3DTrue, _
AddToRecentFiles:=3DFalse, PasswordDocument:=3D"",=20
PasswordTemplate:=3D"", _
WritePasswordDocument:=3D"",=20
WritePasswordTemplate:=3D"", Revert:=3DFalse, _
Format:=3DwdOpenFormatAuto, Connection:=3D"Feuille de=20
calcul enti=E8re", _
SQLStatement:=3D"", SQLStatement1:=3D""
With ActiveDocument.MailMerge
.Destination =3D wdSendToNewDocument
.MailAsAttachment =3D False
.MailAddressFieldName =3D ""
.MailSubject =3D ""
.SuppressBlankLines =3D True
With .DataSource
.FirstRecord =3D wdDefaultFirstRecord
.LastRecord =3D wdDefaultLastRecord
End With
.Execute Pause:=3DTrue
End With
End Sub
J'ai deux questions ?
La m=E9thode consistant =E0 cr=E9er une source de donn=E9es =E0 la=20
fusion dans excel est elle la meilleure ?
Sinon quelle m=E9thode me conseilleriez-vous pour alimenter=20
des champs de donn=E9es dans word =E0 partir d'excel ?
Salut Dan, 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
Hervé.
"dan" a écrit dans le message news: 014301c340b1$2ba10db0$ Bonjour à tous, J'ai crée une macro qui a pour but de préparer dans excel une source de données pour établir une fusiion dans word. A priori l'exécution manuelle se passe correctement mais quand je lance la macro, des messages d'erreur suivant apparaissent : Dans excel : "excel attend la fin de l'execution OLE d'une autre application " dans word : "opération plus longue que prévu, attendre ?" Bref, la macro ne s'execute pas.
voici le code de ma macro
Sub Macro9() ' ' Macro9 Macro ' ' MyAppID = Shell("C:Program FilesMicrosoft OfficeOfficeWinword.EXE C:Base_testxxxxxxxtraitementsRéferentiel_wordDCT.doc" , 1) ActiveDocument.MailMerge.MainDocumentType wdFormLetters Documents.Add DocumentType:=wdNewBlankDocument ActiveDocument.MailMerge.OpenDataSource Name:= _ "C:base_test_gp2 danielphsaTraitements_opcvmTablestable_extraction_word .xls" _ , ConfirmConversions:úlse, ReadOnly:úlse, LinkToSource:=True, _ AddToRecentFiles:úlse, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:úlse, _ Format:=wdOpenFormatAuto, Connection:="Feuille de calcul entière", _ SQLStatement:="", SQLStatement1:="" With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la fusion dans excel est elle la meilleure ? Sinon quelle méthode me conseilleriez-vous pour alimenter des champs de données dans word à partir d'excel ?
Merci d'avance à tous
Salut Dan,
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
Hervé.
"dan" <dan.2@libertysurf.fr> a écrit dans le message news:
014301c340b1$2ba10db0$a101280a@phx.gbl...
Bonjour à tous,
J'ai crée une macro qui a pour but de préparer dans excel
une source de données pour établir une fusiion dans word.
A priori l'exécution manuelle se passe correctement mais
quand je lance la macro, des messages d'erreur suivant
apparaissent :
Dans excel : "excel attend la fin de l'execution OLE d'une
autre application "
dans word : "opération plus longue que prévu, attendre ?"
Bref, la macro ne s'execute pas.
voici le code de ma macro
Sub Macro9()
'
' Macro9 Macro
' '
MyAppID = Shell("C:Program FilesMicrosoft
OfficeOfficeWinword.EXE
C:Base_testxxxxxxxtraitementsRéferentiel_wordDCT.doc"
, 1)
ActiveDocument.MailMerge.MainDocumentType wdFormLetters
Documents.Add DocumentType:=wdNewBlankDocument
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:base_test_gp2
danielphsaTraitements_opcvmTablestable_extraction_word
.xls" _
, ConfirmConversions:úlse, ReadOnly:úlse,
LinkToSource:=True, _
AddToRecentFiles:úlse, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:úlse, _
Format:=wdOpenFormatAuto, Connection:="Feuille de
calcul entière", _
SQLStatement:="", SQLStatement1:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la
fusion dans excel est elle la meilleure ?
Sinon quelle méthode me conseilleriez-vous pour alimenter
des champs de données dans word à partir d'excel ?
Salut Dan, 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
Hervé.
"dan" a écrit dans le message news: 014301c340b1$2ba10db0$ Bonjour à tous, J'ai crée une macro qui a pour but de préparer dans excel une source de données pour établir une fusiion dans word. A priori l'exécution manuelle se passe correctement mais quand je lance la macro, des messages d'erreur suivant apparaissent : Dans excel : "excel attend la fin de l'execution OLE d'une autre application " dans word : "opération plus longue que prévu, attendre ?" Bref, la macro ne s'execute pas.
voici le code de ma macro
Sub Macro9() ' ' Macro9 Macro ' ' MyAppID = Shell("C:Program FilesMicrosoft OfficeOfficeWinword.EXE C:Base_testxxxxxxxtraitementsRéferentiel_wordDCT.doc" , 1) ActiveDocument.MailMerge.MainDocumentType wdFormLetters Documents.Add DocumentType:=wdNewBlankDocument ActiveDocument.MailMerge.OpenDataSource Name:= _ "C:base_test_gp2 danielphsaTraitements_opcvmTablestable_extraction_word .xls" _ , ConfirmConversions:úlse, ReadOnly:úlse, LinkToSource:=True, _ AddToRecentFiles:úlse, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:úlse, _ Format:=wdOpenFormatAuto, Connection:="Feuille de calcul entière", _ SQLStatement:="", SQLStatement1:="" With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la fusion dans excel est elle la meilleure ? Sinon quelle méthode me conseilleriez-vous pour alimenter des champs de données dans word à partir d'excel ?
Merci d'avance à tous
dan
merci Hervé, je vais tester et je ne manquerai pas de te tenir informé. Cordialement
-----Message d'origine----- Salut Dan, 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)
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
Hervé.
"dan" a écrit dans le message news: 014301c340b1$2ba10db0$ Bonjour à tous, J'ai crée une macro qui a pour but de préparer dans excel une source de données pour établir une fusiion dans word. A priori l'exécution manuelle se passe correctement mais quand je lance la macro, des messages d'erreur suivant apparaissent : Dans excel : "excel attend la fin de l'execution OLE d'une autre application " dans word : "opération plus longue que prévu, attendre ?" Bref, la macro ne s'execute pas.
..xls" _ , ConfirmConversions:úlse, ReadOnly:úlse, LinkToSource:=True, _ AddToRecentFiles:úlse, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:úlse, _ Format:=wdOpenFormatAuto, Connection:="Feuille de calcul entière", _ SQLStatement:="", SQLStatement1:="" With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la fusion dans excel est elle la meilleure ? Sinon quelle méthode me conseilleriez-vous pour alimenter des champs de données dans word à partir d'excel ?
Merci d'avance à tous
.
merci Hervé, je vais tester et je ne manquerai pas de te
tenir informé.
Cordialement
-----Message d'origine-----
Salut Dan,
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)
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
Hervé.
"dan" <dan.2@libertysurf.fr> a écrit dans le message news:
014301c340b1$2ba10db0$a101280a@phx.gbl...
Bonjour à tous,
J'ai crée une macro qui a pour but de préparer dans excel
une source de données pour établir une fusiion dans word.
A priori l'exécution manuelle se passe correctement mais
quand je lance la macro, des messages d'erreur suivant
apparaissent :
Dans excel : "excel attend la fin de l'execution OLE d'une
autre application "
dans word : "opération plus longue que prévu, attendre ?"
Bref, la macro ne s'execute pas.
..xls" _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="",
WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="Feuille de
calcul entière", _
SQLStatement:="", SQLStatement1:=""
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la
fusion dans excel est elle la meilleure ?
Sinon quelle méthode me conseilleriez-vous pour alimenter
des champs de données dans word à partir d'excel ?
merci Hervé, je vais tester et je ne manquerai pas de te tenir informé. Cordialement
-----Message d'origine----- Salut Dan, 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)
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
Hervé.
"dan" a écrit dans le message news: 014301c340b1$2ba10db0$ Bonjour à tous, J'ai crée une macro qui a pour but de préparer dans excel une source de données pour établir une fusiion dans word. A priori l'exécution manuelle se passe correctement mais quand je lance la macro, des messages d'erreur suivant apparaissent : Dans excel : "excel attend la fin de l'execution OLE d'une autre application " dans word : "opération plus longue que prévu, attendre ?" Bref, la macro ne s'execute pas.
..xls" _ , ConfirmConversions:úlse, ReadOnly:úlse, LinkToSource:=True, _ AddToRecentFiles:úlse, PasswordDocument:="", PasswordTemplate:="", _ WritePasswordDocument:="", WritePasswordTemplate:="", Revert:úlse, _ Format:=wdOpenFormatAuto, Connection:="Feuille de calcul entière", _ SQLStatement:="", SQLStatement1:="" With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressFieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With End Sub
J'ai deux questions ?
La méthode consistant à créer une source de données à la fusion dans excel est elle la meilleure ? Sinon quelle méthode me conseilleriez-vous pour alimenter des champs de données dans word à partir d'excel ?