Problème d'ouverture document word par VBA Excel

Bonjour,

Je souhaite effectuer un word composé de signet qui seront remplacé par un excel.

Je me suis lancé dans une VBA.

Néanmoins j'ai un problème concernant l'ouverture de ce document word avec les informations renseignés.

    Public Sub GenererConvoc(piLig As Integer)

    Dim iRep As VbMsgBoxResult
    Dim sModele As String
    Dim oShSource As Worksheet
    Dim oWBFinal As Word.Document
    Dim sNomPrenom As String
    Dim sFichierFinal As String

      Set oShSource = Worksheets("Convocation")

    If (oShSource.Range("A" & piLig).Value = "P") Then
    sModele = ThisWorkbook.Path & "\" & "ConvocationP.docx"
    ElseIf oShSource.Range("A" & piLig).Value = "R" Then
    sModele = ThisWorkbook.Path & "\" & "ConvocationR.docx"
    End If

    If Dir(sModele) = "" Then
    MsgBox "Modèle absent : " & vbCrLf & sModele, vbExclamation
    Exit Sub
    End If

    sNomPrenom = oShSource.Range("C" & piLig).Value

    'sFichierFinal

    sFichierFinal = ThisWorkbook.Path & "\" & sNomPrenom & ".docx"

    If Dir(sFichierFinal) = "" Then
        iRep = MsgBox("Voulez-vous générer la convocation de [" & sNomPrenom & "] ?", vbOKCancel + vbExclamation)
    Else
       iRep = MsgBox("Une convocation existe déjà pour [" & sNomPrenom & "] : " & vbCrLf & vbCrLf & sFichierFinal & vbCrLf & vbCrLf & _
                "Voulez-vous la remplacer ?", vbOKCancel + vbExclamation)
    End If

    If iRep <> vbOK Then
        Exit Sub
    End If

    'Ouverture

[b][color=#FF0000]Set oWBFinal = Word.Documents.Open(sFichierFinal)[/color][/b]
oWBFinal.Application.Visible = True

    'alimentation du fichier final avec signets

oWBFinal.Bookmarks("Signet1").Range.Text = oShSource.Range("G1" & piLig).Value 
oWBFinal.Bookmarks("Signet2").Range.Text = oShSource.Range("G2" & piLig).Value 
oWBFinal.Bookmarks("Signet3").Range.Text = oShSource.Range("G3" & piLig).Value
oWBFinal.Bookmarks("Signet4").Range.Text = oShSource.Range("G4" & piLig).Value 
oWBFinal.Bookmarks("Signet5").Range.Text = oShSource.Range("G5" & piLig).Value
oWBFinal.Bookmarks("Signet6").Range.Text = oShSource.Range("B" & piLig).Value 
oWBFinal.Bookmarks("Signet62").Range.Text = oShSource.Range("B" & piLig).Value 
oWBFinal.Bookmarks("Signet7").Range.Text = oShSource.Range("C" & piLig).Value 
oWBFinal.Bookmarks("Signet8").Range.Text = oShSource.Range("D" & piLig).Value 
oWBFinal.Bookmarks("Signet82").Range.Text = oShSource.Range("D" & piLig).Value
oWBFinal.Bookmarks("Signet9").Range.Text = oShSource.Range("E" & piLig).Value
oWBFinal.Bookmarks("Signet92").Range.Text = oShSource.Range("E" & piLig).Value 
oWBFinal.Bookmarks("Signet10").Range.Text = oShSource.Range("G" & piLig).Value 
oWBFinal.Bookmarks("Signet11").Range.Text = oShSource.Range("H" & piLig).Value 
oWBFinal.Bookmarks("Signet12").Range.Text = oShSource.Range("I" & piLig).Value 
oWBFinal.Bookmarks("Signet122").Range.Text = oShSource.Range("I" & piLig).Value 
oWBFinal.Bookmarks("Signet13").Range.Text = oShSource.Range("J" & piLig).Value
oWBFinal.Bookmarks("Signet14").Range.Text = oShSource.Range("K" & piLig).Value 

    Set oWBFinal = Nothing
    Set oShSource = Nothing

    MsgBox "Le bon est disponible !" & vbCrLf & vbCrLf & sFichierFinal, vbInformation, "Bon disponible !"

End Sub

Pouvez-vous m'aider à trouver la cause ?

Merci par avance.

Bonjour,

Tu dois ouvrir une instance de l'application Word (cocher la référence "Microsoft.Word xx.x Object Library" où xx.x est la version) :

Dim AppWord As New Word.Application
'...
'...
Set oWBFinal = AppWord.Documents.Open(sFichierFinal)
AppWord.Visible = True
'...
'...
Rechercher des sujets similaires à "probleme ouverture document word vba"