Bonjour à tous
Je viens vers vous car j'ai comme un petit bug de script....
J'aimerais exporter un tableau d'excel vers Word en utilisant la fonction "replacement", ce qui me permettrait de cibler dans le template l'endroit ou je voudrais qu'il soit collé.
Après plusieurs tentative je n'y suis pas arrivé.
Peut être que vous avez une idée. Il manque pas beaucoup juste le bon code de copie...
Voici le code:
Option Explicit
Dim WS_Gen As Worksheet
Dim Table, T1, T2, T3
Dim objWord As Word.Application
Dim docWord As Word.Document
Dim docWordF As Word.Document
Dim f As Range
Sub Word_Click()
Set objWord = Nothing
Set docWord = Nothing
Table = Sheets("Test").Range("B2:D5").Copy
T1 = Sheets("Test").Cells(8, 1).Value
T2 = Sheets("Test").Cells(8, 3).Value
T3 = Sheets("Test").Cells(8, 5).Value
Dim Fichier As String
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
Set objWord = CreateObject("Word.Application")
Set docWord = objWord.Documents.Open(ThisWorkbook.Path & "\Table.doc")
objWord.Visible = True
objWord.Activate
objWord.Selection.Find.ClearFormatting
With objWord.Selection.Find
.Text = "//t1//"
.Replacement.Text = T1
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objWord.Selection.Find.Execute
objWord.Selection.Find.Execute Replace:=wdReplaceAll
objWord.Selection.Find.ClearFormatting
With objWord.Selection.Find
.Text = "//t2//"
.Replacement.Text = T2
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objWord.Selection.Find.Execute
objWord.Selection.Find.Execute Replace:=wdReplaceAll
objWord.Selection.Find.ClearFormatting
With objWord.Selection.Find
.Text = "//t3//"
.Replacement.Text = T3
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objWord.Selection.Find.Execute
objWord.Selection.Find.Execute Replace:=wdReplaceAll
objWord.Selection.Find.ClearFormatting
With objWord.Selection.Find
.Text = "//table//"
.Replacement.Text = objWord.Selection.Paste
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objWord.Selection.Find.Execute
objWord.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Merci d'avance pour votre aide