OVH Cloud OVH Cloud

Démarer Word depuis Excel

4 réponses
Avatar
Lulu la nantaise
Bonjour à tous,
Est-il possible de lancer WORD depuis une macro Excel et de copier des
données de l'un vers l'autre (d'Excel vers Word), sachant qu'il y a
plusieurs "copiages à faire" ?
Merci beaucoup,
Lulu

4 réponses

Avatar
jb
Bonjour,

Voici un exemple de OLE automation Excel->Word.
A partir d'une lettre type avec des signets, on crée des courriers
personnalisés.

http://cjoint.com/?kFqA4O8AXN

http://cjoint.com/?kFqCl6LwD6

Cordialement JB

Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Range("A2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "malettre.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier malettre.doc doit être dans " &
ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
nom = ActiveCell.Value
rue = ActiveCell.Offset(0, 1).Value
ville = ActiveCell.Offset(0, 2).Value
email = ActiveCell.Offset(0, 3).Value
'--
With doc
.Bookmarks("nom").Range.Text = nom
.Bookmarks("rue").Range.Text = rue
.Bookmarks("ville").Range.Text = ville
End With
nom_doc = ThisWorkbook.Path & "" & nom & ".doc"
doc.SaveAs nom_doc
oApp.Quit
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Lettres crées"
End Sub
Avatar
Lulu la nantaise
Super cool, et quelle rapidité !
A bientôt,
Lulu
"jb" a écrit dans le message de
news:
Bonjour,

Voici un exemple de OLE automation Excel->Word.
A partir d'une lettre type avec des signets, on crée des courriers
personnalisés.

http://cjoint.com/?kFqA4O8AXN

http://cjoint.com/?kFqCl6LwD6

Cordialement JB

Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Range("A2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "malettre.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier malettre.doc doit être dans " &
ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
nom = ActiveCell.Value
rue = ActiveCell.Offset(0, 1).Value
ville = ActiveCell.Offset(0, 2).Value
email = ActiveCell.Offset(0, 3).Value
'--
With doc
.Bookmarks("nom").Range.Text = nom
.Bookmarks("rue").Range.Text = rue
.Bookmarks("ville").Range.Text = ville
End With
nom_doc = ThisWorkbook.Path & "" & nom & ".doc"
doc.SaveAs nom_doc
oApp.Quit
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Lettres crées"
End Sub
Avatar
Lulu la nantaise
Encore une petite question, je ne parviens pas à coller ce que j'ai copier
dans Word ....
Peux-tu encore m'aider ?
Merci beaucoup ...
"Lulu la nantaise" a écrit dans le message de
news:%
Super cool, et quelle rapidité !
A bientôt,
Lulu
"jb" a écrit dans le message de
news:
Bonjour,

Voici un exemple de OLE automation Excel->Word.
A partir d'une lettre type avec des signets, on crée des courriers
personnalisés.

http://cjoint.com/?kFqA4O8AXN

http://cjoint.com/?kFqCl6LwD6

Cordialement JB

Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Range("A2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "malettre.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier malettre.doc doit être dans " &
ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
nom = ActiveCell.Value
rue = ActiveCell.Offset(0, 1).Value
ville = ActiveCell.Offset(0, 2).Value
email = ActiveCell.Offset(0, 3).Value
'--
With doc
.Bookmarks("nom").Range.Text = nom
.Bookmarks("rue").Range.Text = rue
.Bookmarks("ville").Range.Text = ville
End With
nom_doc = ThisWorkbook.Path & "" & nom & ".doc"
doc.SaveAs nom_doc
oApp.Quit
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Lettres crées"
End Sub




Avatar
Lulu la nantaise
Excuse pour la deuxième intervention, c'était une erreur qui n'avait rien à
voir ....
Merci encore ça marche du feu de Dieu !
Lulu

"Lulu la nantaise" a écrit dans le message de
news:
Encore une petite question, je ne parviens pas à coller ce que j'ai copier
dans Word ....
Peux-tu encore m'aider ?
Merci beaucoup ...
"Lulu la nantaise" a écrit dans le message
de

news:%
Super cool, et quelle rapidité !
A bientôt,
Lulu
"jb" a écrit dans le message de
news:
Bonjour,

Voici un exemple de OLE automation Excel->Word.
A partir d'une lettre type avec des signets, on crée des courriers
personnalisés.

http://cjoint.com/?kFqA4O8AXN

http://cjoint.com/?kFqCl6LwD6

Cordialement JB

Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Range("A2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "malettre.doc"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier malettre.doc doit être dans " &
ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
nom = ActiveCell.Value
rue = ActiveCell.Offset(0, 1).Value
ville = ActiveCell.Offset(0, 2).Value
email = ActiveCell.Offset(0, 3).Value
'--
With doc
.Bookmarks("nom").Range.Text = nom
.Bookmarks("rue").Range.Text = rue
.Bookmarks("ville").Range.Text = ville
End With
nom_doc = ThisWorkbook.Path & "" & nom & ".doc"
doc.SaveAs nom_doc
oApp.Quit
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Lettres crées"
End Sub