Copy all charts from excel into an existing powerpoint - excel

I have 35 excel files that each have 50 charts in them (all on the same sheet). I need to copy each of the charts over to a powerpoint file, which is already made with specific formatting and labels for positioning of the charts. How would I go about writing a script that will reference all of the charts in the respective excel file and then send them to the powerpoint at specific locations and page numbers of the powerpoint, some being differently sized?
I am assuming a forloop for referencing each of the charts, then an explicit code for each chart once numbered in the forloop to resize and place at specifc locations in the powerpoint.
Once I get an idea of how to reference each of the charts, resize and then place at specific point in the ppt slide, I can automate the entire thing.

Please note that StackOverflow is not a coding service. Bearing that in mind this is how I would go about it:
1. Put placeholders in the PowerPoint. These placeholders contain a unique identifier of each chart object (e.g. Workbook1.Sheet1.Chart1). I would make sure they are sized as your chart would be in the end (width & height) and that they are invisible. I would use rectangles with 100% transparency, and use the Alt Text property.
2. Write a sub that deletes all charts but keeps all placeholders in your PowerPoint file.
3. Write a function that retrieves the charts per placeholder.
4. Write a sub that copies the chart object and pastes it as a picture.
5. Write a sub that loops through all placeholders in your file, gets and pastes all charts.

Related

Copy-paste from Excel to PowerPoint via VBA: Align two pictures

I'm using VBA to copy-paste ranges from Excel into PowerPoint. I have three Excel sheets from which I copy two different things: the data and the annotations. On the PowerPoint slides, data and annotations are supposed to be next to each other, data on the left, annotations on the right. However, these sections are of different sizes. I have no problem putting the data on the slides with the help of a for each loop, but how do I get the annotations to fit snugly to the right of the data?
Right now I have three sections of very similar code for the three different sheets because I don't know how to align data and annotations without manually defining myShape.Top and myShape.Leftfor annoations. Is there a way to tell PowerPoint "Put this picture next to the other picture?"

Powerpoint: Linking Excel charts & updating them or deleting old charts & inserting updated ones?

I have a PowerPoint presentation containing Excel charts and .png files. This presentation needs to be updated fairly often and I’d like to use VBA for this. However, I’ve read up on linking charts from Excel to Powerpoint and it seems not to be bug-free, but I don't really know anything about it.
So I need advice what makes the most sense because I don't have any experience with this. Is updating the charts usually not an issue? Or would it be more fool-proof to delete the old charts and insert the new ones? In case it's the latter, would I simply define the dimensions of the chart or does the use of placeholders offer any advantages?
What I've done in the past is use VBA to paste pictures of the charts into the slides. Then the presentation serves as a snapshot, and I don't need to worry about links.
You can set up a table with details like chart name, worksheet name, slide number, image size (width, height) and position (left, top). Then the code moves down the list, finding the worksheet, copying the chart, activating the slide, pasting the chart as a picture, moving it into position. Best results are when the chart is sized right in Excel so you don't need to resize it in PowerPoint.
It's been a while, so I don't have that code at my fingertips. I'll hunt around when I have a chance.

Excel: How do I view the source data of a graph from excel in word?

I wanted to paste the graph from excel in word such that it is possible for me to view the source data of the graph.
What I did is to copy the graph from excel and paste it as link in word. I have two or more graph in the excel file (located in the same sheet). When I double click the graph in word it would take me to sheet of where the graph is located but not actually the graph.
What shall I do in order to be able to achieve what I want? That is when I click on the graph it would take me to its source?
So, if you have got your Chart created in let's say a workbook saved at C:\temp\foo.xlsx, now you copy and paste the chart in Word.
Using VBA in Word
Example
Sub ShowChartData()
With ActiveDocument.InlineShapes(1).Chart.ChartData
.ActivateChartDataWindow
End With
End Sub
Without VBA.
To view the data, make sure the Workbook is not open, then just Right Click the chart and click Edit data, Word will launch your workbook foo.xlss and select the exact range containing the chart data.

VBA Excel Chart to powerpoint - saving file as multiple outputs

I have a template in excel, and a powerpoint template.
in the powerpoint template I have several charts linked to the excel template.
I want to make a loop that changes something in excel, so that the chart updates, "saveas" for both the excel and powerpoint file, so I have eg. 100 different excel files and 100 different powerpoint files, all build on the templates. I want to be able to manually alter some data in those 100 excelfiles, with the link to powerpoint still intact, so they are updated too if needed.
however, when I open the powerpoint templates, right click on a chart and select "edit data", then the chart is still linked to the excel template, not the saveas version of the excel file?
how do I change the link of a chart in powerpoint, to a different excel filename? the structure in the two excel files are identical.
the chart is created in excel and copy/pasted as "keep source formatting and chain data" (translated from danish)
any help would be greatly appreciated.
I have also tried a solution where the copy/paste is done via vba into an empty powerpoint template, but that is more time consuming, and powerpoint often crashes.
Assuming you have a reference to the shape represented by the linked chart in oSh, this will show you the link:
Debug.Print oSh.LinkFormat.SourceFullName
And this will change it to some other file:
oSh.LinkFormat.SourceFullName = "c:\some\path\yourfile.xls"
Most likely there will also be a !chartname or the like after yourfile.xls ... you'll need to include that.
And save the Excel files first, THEN change the link in the PPT to point to them. If you change the link to point to a non-existent file, PPT won't throw any errors; it'll simply leave the link unchanged.

Using macros to format charts in excel

I'm trying to create a macro that will format charts in Excel so that all of my charts have the same formatting, but different data. Usually I would just paste the formatting, but these charts were made using a plugin and they do not appear to be compatible with 'paste formats'. Each chart is in a different worksheet along with the chart data.
My charts have 3 series. Each series has a particular format e.g.
series 1: circular marker, size-3pt, no marker line, green fill.
series 2: circular marker, size-3pt, black marker line, yellow fill.
series 3: circular marker, size-3pt, no marker line, red fill.
Also, the charts need to be a specific size for presentation (no sure exact sizes yet, but presumably that should be easy to edit).
These are the only parameters that I need to change from the default in order to get the charts to look how I want them. Can anyone help?
Chart formatting can be done fairly easily with VBA:
Dim chChart as chart
set chChart = Thisworkbook.Sheet("Sheet1").ChartObjects("Chart1").Chart
With chChart
seriescollection(1).Markerforegroundcolor = rgb(255,255,255)
seriescollection(1).Markerbackgroundcolor = rgb(255,255,255)
seriescollection(1).interior.color = rgb(255,255,255)
End With
The above code should give you an idea of how to write the macro, substituting the correct sheet and chart names. Ideally you would also use some loops to loop through you charts and series within the charts
For each chart in Thisworkbook.Sheet("Sheet1").ChartObjects
For each series in chChart.seriescollection
To get the exact values you want to change I would suggest either recording a macro of you making the changes manually or using the Editor Object Browser (F2 in the VBA Editor) to find the likely values.

Resources