Hi all,
I'm trying to automate the filling of a word template contract and I keep getting the 462 run-time error. The debug gives me the error colored in red below. I'm hoping for some directions on how to correct my code. I've tried couple of things already but nothing seems to be working. Could the problem be linked to authorisation problems ? The template is on a OneDrive but the authorizations should be fine.
Thanks in advance,
I'm trying to automate the filling of a word template contract and I keep getting the 462 run-time error. The debug gives me the error colored in red below. I'm hoping for some directions on how to correct my code. I've tried couple of things already but nothing seems to be working. Could the problem be linked to authorisation problems ? The template is on a OneDrive but the authorizations should be fine.
Thanks in advance,
Rich (BB code):
Sub RemplirContrat()
Dim appWord As Object
Dim doc As Object
Dim contratTemplate As String
contratTemplate = "C:\Users\...."
Set appWord = CreateObject("Word.Application")
appWord.Visible = True
Set doc = appWord.Documents.Open(contratTemplate)
If Not doc.ReadOnly Then
doc.Content.Select
appWord.Selection.Copy
Set doc = appWord.Documents.Add
doc.Range.Paste
End If
With doc.Content.Find
.Execute FindText:="<<Date entrée en vigueur>>", ReplaceWith:=Cells(2, 1).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Nom Société>>", ReplaceWith:=Cells(2, 2).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Adresse>>", ReplaceWith:=Cells(2, 3).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Numéro Entreprise>>", ReplaceWith:=Cells(2, 4).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Représentant>>", ReplaceWith:=Cells(2, 5).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Fonction>>", ReplaceWith:=Cells(2, 6).Value, Replace:=wdReplaceAll
.Execute FindText:="<<<<% dispense>>", ReplaceWith:=Cells(2, 7).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Titre Client>>", ReplaceWith:=Cells(2, 8).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Forme Sociale>>", ReplaceWith:=Cells(2, 9).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Place de signature>>", ReplaceWith:=Cells(2, 10).Value, Replace:=wdReplaceAll
.Execute FindText:="<<Date du jour>>", ReplaceWith:=Cells(2, 11).Value, Replace:=wdReplaceAll
.Execute FindText:="<<DPO ou Personne de contact>>", ReplaceWith:=Cells(2, 12).Value, Replace:=wdReplaceAll
End With
doc.SaveAs "C:\..."
appWord.Documents(contratTemplate).Close False
appWord.Quit
Set doc = Nothing
Set appWord = Nothing
End Sub
Last edited by a moderator: