Excel VBA - Replace chart marker with picture

I would like to replace the markers of a line chart with a picture in VBA.

This is equivalent to:

enter image description here

I copied/pasted this picture in a sheet of the workbook and called it picture.

With .ChartObjects("graph").Chart
    .SeriesCollection(1).MarkerStyle = xlMarkerStylePicture
    ...
End With

What should I use to replace ... and point to my image?

Thanks

2 answers

  • answered 2019-04-18 17:54 Ryan B.

    If you're using something on your files system then you can use this:

    With .ChartObjects("graph").Chart
        .SeriesCollection(1).MarkerStyle = xlMarkerStylePicture
        .SeriesCollection(1).Format.Fill.UserPicture "C:\...your path...\pic.png"
    End With
    

  • answered 2019-04-19 09:49 Maxbester

    Thanks to Cyril's suggestion I managed to copy/paste the picture to replace the last point of the serie. The code is:

    Sheets("param").Shapes("picture").CopyPicture
    With .ChartObjects("graph").Chart
        .Points(.Points.Count).Paste
    End With
    

    If anybody has a better solution feel free to post it!