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?
Related
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.
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
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? :)
I have a spreadsheet on my Google Account and I have some code which edits cells in this spreadsheet. Now I'm looking for a way to edit and(/or) make a new Chart in the worksheet I'm working on. I'm using the Google Spreadsheet API to edit the cells.
I did some hours of research on this topic but I just can't find how it would work. My understanding is that it is impossible with this API to work with charts. Is this correct?
I also found something about a Visualization api, but I can't figure out how to get this to work in vb, let alone how to make sure the chart I create would end up in my spreadsheet.
I want to use this chart on my own website, and I don't want to have to run the code before the graph updates. In other words, when I change the information in the cells manually via my spreadsheet I want these numbers to end up in my chart. I only want to change the chart via my code when I need to add a row or column to the chart.
Lastly, I've also read it is not possible at all to edit charts in a spreadsheet via a program. If so, I'd like to say to Google: WHY NOT!! AARGH. And maybe someone can suggest an other way to automatically update a chart which I can place on my website. (Again I want a live representation of the spreadsheet and the code I'm creating will only be run once a day if at all).
Thanks you so much for your time!
Google have Script inside the Spreadsheets that can do that for you.
https://developers.google.com/apps-script/reference/charts/
I'm currently considering a number of options for copying an excel sheet into a powerpoint presentation.
Using VBA select a excel sheet, copy the range and place it into a newly created powerpoint slide as an image.
I create excel automated html of a sheet, once that html is saved(initially), i create an image off of the html.
Using VSTO, i open Excel copy each object and paste it into a new powerpoint slide, using the clipboard(or another copy method).
These operations will be called frequently, by many different users - all the actual operation occurs on a single server.
What would the pros and cons of each approach be? Are there any prefered or better optimized techniques available?
Option 1:
Pro:
Speed
Contra:
The inserted Data can't be copied, altered, viewed within excel etc.
Option 3:
A couple of years ago I wrote a similar VBA-Procedure that created a >1000 Slides Presentation from an Excel Sheet. The method was called from Excel and went AFAIR like this(pseudo-code):
newSlide = PowerPoint.AddSlide
embeddedSheet = newSlide.Add OLEObject(Excel-Sheet)
embeddedSheet.Range(..., ...) = srcSheet.Range(..., ...)
someFormating(embeddedSheet)
createPieChart(embeddedSheet.Range(..,...))
resize(embeddedSheet)
embeddedSheet.Save
embeddedSheet.Close
Pro / Contra based on my experience with the method above.
Pro:
The Sheet is embedded in PowerPoint
you can alter the Data and run Macros on it.
you do not need to keep the original Excel sheet.
Contra:
The Output-File is bigger
The Process uses a lot of RAM.
The Process takes relatively long. AFAIR 1k Slides took about 10 Minutes on the computer in my office. Creating the OleObject took the majority of the time.