Word VBA 刷新嵌入的 Excel 图表 [英] Word VBA to refresh embedded Excel chart
问题描述
我在 Word 文档中嵌入了图表.当我更新Excel中的数据时,使Excel工作簿中的图表更新,然后进入Word文档,我可以手动选择嵌入图表,选择设计>刷新数据,Word中的嵌入图表更新以显示新数据.
I have embedded charts in a Word doc. When I update the data in Excel, so that the chart in the Excel workbook updates, and then go to the Word doc, I can manually select the embedded chart, select Design > Refresh Data, and the embedded chart in Word updates to show the new data.
当我尝试录制 Word VBA 来执行此操作时,它不会让我执行这些操作.
When I try to record the Word VBA to do that, it won't let me do those actions.
我在 Word 的对象浏览器中查看了所有我能想到的地方.我看到我可以像这样识别嵌入的图表:
I've looked everywhere I can think of in Word's object browser. I see that I can identify the embedded chart like this:
thisdocument.InlineShapes(1)
但我不知道如何刷新它.我需要做什么?
But I don't see how to refresh it. What do I need to do?
推荐答案
我在这里找到了答案:
thisdocument.InlineShapes(1).LinkFormat.Update
它在我的测试中运行良好.
It worked fine in my tests.
并在更新后断开链接(在 word 模板中),以避免在稍后运行显示不同数据时无意中将图表更新为一个:
And to break the link (in the word template) after updating, to avoid inadvertently updating the chart to one from a later run showing different data:
thisdocument.InlineShapes(1).LinkFormat.BreakLink
这篇关于Word VBA 刷新嵌入的 Excel 图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!