Problème lancement macro

Bonjour,

J'ai un projet qui consiste à ouvrir des graphiques crées sur excel et à les afficher sur Word.

Je suis tombé sur ce code qui normalement devrait marcher, mais ça me renvoie toujours la même erreur.

"Type défini par l'utilisateur non défini".

Sub Test36()
'
' Test36 Macro
'

    'Name of an existing Word document, and the name the chart will have when exported.
    Const stWordDocument As String = "Testmacro06022020.docx"
    Const stChartName As String = "Graphique.gif"

    'Word objects.
    Dim wdApp As Excel.Application
    Dim wdDoc As Excel.Document
    Dim wdbmRange As Word.Range

    'Excel objects.
    Dim wbBook As Workbook
    Dim wsSheet As Worksheet
    Dim ChartObj As ChartObject

    'Initialize the Excel objects.
    Set wbBook = ThisWorkbook
    Set wsSheet = wbBook.Worksheets("Feuil1")
    Set ChartObj = wsSheet.ChartObjects("Graphique 1")

    'Turn off screen updating.
    Application.ScreenUpdating = False

    'Export the chart to the current directory, using the specified name, and save the chart as a .gif
    ChartObj.Chart.Export _
                   FileName:=wbBook.Path & "\" & stChartName, _
                   FilterName:="GIF"

    'Initialize the Word objects to the existing Word document and bookmark.
    Set wdApp = New Word.Application
    Set wdDoc = wdApp.Documents.Open(wbBook.Path & "\" & stWordDocument)
    Set wdbmRange = wdDoc.Bookmarks("ChartReport").Range

    'If there is already an inline shape, that means the macro has been run before - clean up any artifacts.
    On Error Resume Next
    With wdDoc.InlineShapes(1)
        .Select
        .Delete
    End With
    On Error GoTo 0

    'Add the .gif file to the document at the bookmarked location,
    'and ensure that it is saved inside the Word doc.
    With wdbmRange
        .Select
        .InlineShapes.AddPicture _
        FileName:=wbBook.Path & "\" & stChartName, _
        LinkToFile:=False, _
        savewithdocument:=True
    End With

    'Save and close the Word document.
    With wdDoc
        .Save
        .Close
    End With

    'Quit Word.
    wdApp.Quit

    'Clear the variables.
    Set wdbmRange = Nothing
    Set wdDoc = Nothing
    Set wdApp = Nothing

    'Delete the temporary .gif file.
    On Error Resume Next
    Kill wbBook.Path & "\" & stChartName
    On Error GoTo 0

    MsgBox "Chart exported successfully to " & stWordDocument

End Sub

Merci d'avance pour aide.

5classeur1.xlsx (13.12 Ko)

C'est bon j'ai trouvé, il suffisait d'activer "Microsoft Word" dans les références de VBA.

Rechercher des sujets similaires à "probleme lancement macro"