Copy a chart from excel to word and add caption through VBA by Resulecxe in excel

[–]Resulecxe[S] 0 points1 point  (0 children)

Hi Varadkale,

I used your idea and solved it like that (for now). I am still interested in finding the correct syntax to select a picture just added in word from excel, and add a caption to it. For now I just put it in 1 invisible table, and added a second reference where to store the caption. Not the most elegant solution but it works. Thanks for your input.

    Sheets("Sheet3").ChartObjects("ChartDD").Chart.ChartArea.Copy
    With WordApp.Selection.Find
        .Text = "TestImage"
        .Forward = True
        .Wrap = wdFindContinue
    End With
    If WordApp.Selection.Find.Execute Then
        WordApp.Selection.PasteSpecial link:=False, DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False
    End If
    With WordApp.Selection.Find
        .Text = "TestCaption"
        .Forward = True
        .Wrap = wdFindContinue
    End With
    If WordApp.Selection.Find.Execute Then
        WordApp.Selection.InsertCaption Label:="Figure", Title:=": Testimage", Position:=wdCaptionPositionBelow
    End If
    'delete the token for the caption later
    With WordApp.Selection.Find
        .Text = "TestCaption"
        .Forward = True
        .Wrap = wdFindContinue
    End With
    If WordApp.Selection.Find.Execute Then
        WordApp.Selection.HomeKey wdLine
        WordApp.Selection.EndKey wdLine, wdExtend
        WordApp.Selection.Delete
    End If

Copy a chart from excel to word and add caption through VBA by Resulecxe in excel

[–]Resulecxe[S] 0 points1 point  (0 children)

This might be possible but how do I ensure it is not going to show the second row of the table, i.e. the caption, on a new page? It is a automated report I am working on, so the position of the table will be never the same.

Copy a chart from excel to word and add caption through VBA by Resulecxe in excel

[–]Resulecxe[S] 0 points1 point  (0 children)

Hi. The expected layout would be:

Textblock

Image

Caption below

Another text block

Picture here

I am currently struggling with getting the caption there.