Word VBA to refresh embedded Excel chart

北战南征 提交于 2020-06-18 11:50:07

问题


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.

When I try to record the Word VBA to do that, it won't let me do those actions.

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?


回答1:


I found the answer here:

http://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-msoffice_custom/what-is-the-vba-equivalent-of-refresh-data-for/b8405aca-716a-e011-8dfc-68b599b31bf5

thisdocument.InlineShapes(1).LinkFormat.Update

It worked fine in my tests.

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


来源:https://stackoverflow.com/questions/40895647/word-vba-to-refresh-embedded-excel-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!