1 pièce(s) jointe(s)
rapatriement excel vers fichier word
Bonjour a tous
J’aimerai d’une fiche excel rapatrier les information dans un formulaire
Les information a rapatrier : ( fichier fiche agent.xls)
Nom situé en B21
Prenom situé en B22
Matricule situé en B19
Restriction1 situé en F51
Restriction 2 situé en F53
Restriction 3 situé en F54
Sur ma fiche Excel j’aimerai crée un bouton qui m’ouvre mon formulaire avec les information rentré au bonne endroit.
un code test (je sais pas du tout si il est bon)
sa me met l'erreur suivante "type defini par lutilisateur non defini"
Code: Tout sélectionner
Code:
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
| Private Sub CommandButton4_Click()
Dim NDF As String, NDF2 As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
NDF = ActiveWorkbook.Path & "C:\Documents and Settings\rm715079\Bureau\Inaptitude\formulaire3.dot"
NDF2 = ActiveWorkbook.Path & "C:\Documents and Settings\rm715079\Bureau" & Sheets("fiche agent").Range("B19").Text & ".doc"
On Error Resume Next
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open(NDF, ReadOnly:=False)
With WordApp
.Visible = False
.Selection.Goto What:=wdGoToBookmark, Name:="nom"
.Selection.TypeText Text:=Sheets("fiche agent").Range("B21").Value
.Selection.Goto What:=wdGoToBookmark, Name:="prenom"
.Selection.TypeText Text:=Sheets("fiche agent").Range("B22").Value
.Selection.Goto What:=wdGoToBookmark, Name:="matricule"
.Selection.TypeText Text:=Sheets("fiche agent").Range("B19").Value
.Selection.Goto What:=wdGoToBookmark, Name:="prenom"
.Selection.TypeText Text:=Sheets("fiche agent").Range("B22").Value
.Selection.Goto What:=wdGoToBookmark, Name:="restriction1"
.Selection.TypeText Text:=Sheets("fiche agent").Range("F51").Value
.Selection.Goto What:=wdGoToBookmark, Name:="restriction2"
.Selection.TypeText Text:=Sheets("fiche agent").Range("F53").Value
.Selection.Goto What:=wdGoToBookmark, Name:="restriction3"
.Selection.TypeText Text:=Sheets("fiche agent").Range("F55").Value
End With
WordDoc.Application.ActiveDocument.SaveAs NDF2
WordApp.Application.Quit
Set WordDoc = Nothing
Set WordApp = Nothing
End Sub |
merci .