Word VBA to refresh embedded Excel chart - vba

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?

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

Related

Excel VBA Chart Generation using Predetermined Templates

I am new to VBA coding, and I have to automate the creation of different charts of 10+ tables of data. The chart design has to be completely the same as it was when it was done manually.
While I did try to use record macros to create the exact type of chart I need for each table, it doesn't generate the same results. Tweaking the code also takes ages for each chart individually.
While saving the wanted chart types as templates does do the trick for only one user, is it possible to somehow save them as templates in the workbook that is being used, so that the code doesn't break when it is sent to other colleagues to update the charts by adding new data?

Is it possible to extract the format options of an Excel chart into VBA code?

I am writing a macro that will automatically create a chart based off some data in a table. However, the chart format that I need to use is very complicated (20 columns of data all displayed in a particular custom format), and I don't know how to recreate that format with the chart editor, let alone VBA.
Basically, I want to be able to take an example of this chart format, and somehow get the VBA code that one would use to create a chart of this format directly in VBA, so I can include this code in the macro.
I was considering making a chart template .crtx file and including it with the spreadsheet in a .zip when the user downloads it, but templates seem to only work when they are located under User\AppData\Roaming\Microsoft\Templates\Charts, and I don't want to put the user through having to manually move this file for the macro to work. Alternatively, if anybody knows how to get a template to work when it isn't installed in this location that would be great as well!
Thanks in advance.
Include the chart with the original format in the workbook when you send it, and put the example chart on a sheet that is very hidden.
Then, write your macro such that it creates a chart of the same type with the new data and copies the formatting of the original chart.
How to make a sheet "very hidden": https://www.excel-university.com/make-an-excel-worksheet-very-hidden/
How to copy chart formatting: https://www.officetooltips.com/excel_2016/tips/a_quick_way_to_duplicate_all_of_the_custom_chart_formatting.html
Note: If you're struggling with how to use vba to copy the chart formatting, record a macro while executing the instructions at the second link.

Generate PowerPoint presentations with Excel sheets / charts embedded in it programatically

So what my client wants to accomplish seems pretty simple. We will have PPTX file template with a few Excel sheets embedded in it, and a few charts too.
We have created such template file. We are able to extract it, update excel files that sit in ppt/embedded directory with new ones, and pack it back.
The problem is, the display values of the tables or charts do not update automatically when such file is opened. You have to double click on a spreadsheet table or chart to trigger "edit mode". When you leave it the charts are updated.
We figured that internally, PowerPoint is doing screenshots of tables or charts, and uses it to display presentation. This is probably to allow presentation players that do not come with Excel to correctly render the presentation with embedded sheets.
Is there a way I can programatically update the screenshots of tables/charts? Is there some sort of API from Microsoft that would allow me to do that, like "MS Office API".
Maybe there is some way to have MS office configured/scripted, so I send it a file, it runs a VB script on it and returns updated value? I figured I can actually trigger update to screenshots with VB script. But I don't know if I can orchestrate Office program to do what I want.
Help? :)

Locking text fields in embedded document

I have been tasked with updating a spreadsheet that produces a report by replacing text in a template. Previously, the worksheet referenced an outside/separate file-- my job is to get it working in an embedded document.
I currently have text form fields for every input I want to insert within the embedded document template. As it stands, users can edit the document template however they like, but if they accidentally erase a text form field (again, where text is replaced via the vba macro) then it will break the macro and the spreadsheet will be useless.
My question:
Is there some way to lock or protect text form fields such that the rest of the document is editable? I essentially want to have the inverse of a "text form field only" protection.
Alternatively, is there a better way to approach this project? I'm thinking of leaving the spreadsheet as is, but including a "reset" button bringing the template back to it's original state if anything breaks. If I did this method, this would require there NOT to be an external file. Attempts to do this so far have proven unsuccessful.
My general methodology/algorithm goes as follows:
Open the reference document
Replace all the text form fields via bookmarks with plain text,
making sure to reassign the bookmarks afterward (so as to not lose
them if they run the macro more than once).
Save the embedded document as a .doc with the inputs inserted
Replace all bookmarked inputs with text form fields to return the
template to its original state
Any information would be IMMENSELY appreciated. I am slowly running out of time and am feeling stuck.
Many thanks!
-Sooji

Link Dynamic SQL Chart In Powerpoint

I'm working on a project that needs to be displayed via Powerpoint. I have a SQL chart that is refreshed every morning at 9 am and 12 pm with updated results. I need this information to display within a Powerpoint slideshow for our team, but I'm not sure how to do this where I can see the updated results. I tried inserting the excel spreadsheet as an object and linking that way, but that has not worked.
If the chart is in Excel and automatically refreshes, try it like so:
First, make sure that the PPT file and the XL file are in the same folder if possible.
Select the chart in Excel and rightclick/copy.
Switch to PowerPoint.
Use Paste Special and put a check next to Link to paste the chart into PPT.
I would paste it onto a slide that does NOT have a content placeholder; delete it or put some text into it if one's already there, then paste the chart.
PowerPoint should now update the chart each time you open the presentation, assuming the data/chart have changed in XL.