1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
Sub CopierCollerDansWord()
Dim AireSource As Range
Dim I As Long, J As Long, DerniereLigne As Long
Dim WordApp As Object, WordDoc As Object
Dim CheminWord As String, NomDoc As String
Dim HeureDebut, HeureFin, TempsTotal
On Error GoTo Fin
Application.ScreenUpdating = False
HeureDebut = Timer
CheminWord = ActiveWorkbook.Path & "\Cellule en Html.docm" ' A adapter
With Sheets("Feuil1")
DerniereLigne = .Cells(.Rows.Count, 1).End(xlUp).Row
Set AireSource = .Range(.Cells(2, 1), .Cells(DerniereLigne, 1))
End With
Set WordApp = CreateObject("word.Application")
With WordApp
.Visible = True
Set WordDoc = .Documents.Open(CheminWord)
For J = 1 To AireSource.Count
AireSource(J).Offset(0, 1).Copy
For I = 1 To WordDoc.contentcontrols.Count
If AireSource(J) = WordDoc.contentcontrols(I).Title Then
WordDoc.contentcontrols(I).Range.Paste
Exit For
End If
Next I
Next J
' WordDoc.Close savechanges:=True
End With
Application.ScreenUpdating = True
HeureFin = Timer
TempsTotal = HeureFin - HeureDebut
Debug.Print "Temps total du traitement : " & Round(TempsTotal, 0) & " seconde(s)"
GoTo Fin
Fin:
Application.ScreenUpdating = True
' WordApp.Quit
Set WordApp = Nothing: Set WordDoc = Nothing
Set AireSource = Nothing
End Sub |
Partager