[英]copy Charts excel to specific paragraphs word with VBA
I have a word file that contains text.我有一个包含文本的 word 文件。 And I have an Excel file that has several charts.
我有一个包含多个图表的 Excel 文件。 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.我知道如何在 word 文件中复制图表,但不知道在特定段落中。 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).
下面的代码只是把图复制到word文件中,但是它的position不能调整(比如应该在哪个段落)。
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.最后,我明白了问题的答案,像下面的代码一样使用段落 object 就足够了。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.