After I have updated the series on a chart I have been trying to copy and paste an image of the chart into a PowerPoint using VBA. As soon as the image is pasted I want to rename the image. There will be many images of previous charts already on the PowerPoint. As soon as I paste the image I was thinking I could rename using code such as below while the picture is active.
With ActiveShape
.name="Batch1"
end with
I keep getting "Object Required" error messages. How can I accomplish what I am trying to do?
Related
The code I am running opens up a workbook and copies a chart from it and pastes it into a PowerPoint slide. Following this, it will open up another workbook of apparently identical format, copy a chart and similarly paste it into PowerPoint.
The issue: The first graph is successfully copied and pasted into PowerPoint, however when I open up the second workbook and set it to the active workbook there is an issue with running the following code:
ActiveWorkbook.Charts("Chart1").ChartArea.Copy
I get the error:
Run-time error '9':
Subscript out of range.
I have checked the opened workbook and there is a graph within it. I think the issue may be that the graph in the second workbook may not be named "Chart1" however I am not sure how to find this out.
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.
I have tried to copy a excel range and paste as table format in powerpoint using excel vba. It pasting the range but when I resize the table the Powerpoint application is crashing.
Your solution helped me to get rid of chrasing powerpoint application. I wrote the table resize function in powerpoint file and executed it.
Thanks alot...
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.
I am having trouble copying and pasting some excel charts as pictures and recieving the error: "1004 "Microsoft Excel cannot paste the data." My code finds a premade chart, updates the range, copies the chart, and pastes it into another sheet. The weird thing is that this error is inconsistent where sometimes it will paste a certain chart as a picture and sometimes it won't. I can use similiar code to copy to word with no problems, and if I use the basic copy function, it can repaste as a chart.
This is the functions I am using to copy a chart and paste as a picture:
chtObj.CopyPicture xlScreen, xlPicture
PasteSheet.Paste
If there is something obvious I am missing or if there any work arounds I am open to ideas
Thank you
I have found that for very large points of data it is very easy for excel to lose reference to those points. So if you copy and paste a picture I believe it still in some way keeps a link to those data points which then could be volatile and cause the 1004 error to pop up. My Work around with the help of Floris, chuff, and other SO members was to copy the chartArea and paste using the pastespecial method
ActiveSheet.ChartObjects(chtName).Activate
ActiveChart.ChartArea.Copy
PasteSheet.Select
PasteSheet.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
Unfortunately it seems the only way to paste to another sheet using pastespecial formatted to bitmap is to select the sheet first paste then re-select the sheet you copied from.
The only thing that worked for me was Paste Special then "XML Spreadsheet". It preserved the integrity of the spreadsheet with my dates and dollar amounts and links to websites.