简体   繁体   中英

copy Charts excel to specific paragraphs word with VBA

I have a word file that contains text. And I have an Excel file that has several charts. I want these charts to be copied in specific paragraphs. For example, the first chart in the fifth paragraph and the second chart in the tenth paragraph and...

I know how to copy a chart in a word file, but not in a specific paragraph. The following code only copies the diagram into the word file, but its position cannot be adjusted (for example, in which paragraph it should be).

   Set chObject = wb1.Worksheets("Sheet1").ChartObjects(c1) 

   chObject.CopyPicture xlScreen, xlPicture

        On Error Resume Next
        Do
            Err.Clear
            WordRange.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine, DisplayAsIcon:=False
            DoEvents
            If Err.Number <> 0 Then Application.Wait DateAdd("s", 1, Now)
        Loop While Err.Number <> 0
        On Error GoTo 0
        

Can anyone help?

Finally, I understood the answer to the problem, it is enough to use the paragraph object like the code below. The following code copies the diagram in the fifth paragraph

   chObject.Chart.ChartArea.Copy

           myDoc.Paragraphs(10).Range.PasteSpecial Link:=False, _
            DataType:=wdPasteMetafilePicture, _
            Placement:=wdTight, _
            DisplayAsIcon:=False

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM