How can I identify if the chart exists in a worksheet - excel

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.

Related

EXCEL Workbook creating phantom worksheets that can't be deleted

I have an Excel workbook with some VBA code in modules and in the worksheets. As I use the workbook, Excel will suddenly create ghost/phantom worksheets that can't be deleted. IN the screen shot below the original works sheets, Sheet17 (Main Menu ) and Sheet 25 (Results) ended up getting duplicated (Sheet17, Sheet171, Sheet1711, Sheet 17111; Sheet25, Sheet251, Sheet2511, Sheet25111, etc). The version less than Sheet17111 are ghost worksheets (notice the different icon) that can not be deleted. The VBA code for those worksheets stayed with the latest version of the worksheet (ie. Sheet17111).
The only way to get rid of the ghost worksheets is to save the workbook as an xlsx, close the workbook open up the xlsx, copy over the worksheet code and modules and save out the xlsm. Of course this only corrects the problem until the next occurrence
I am not calling any special addins.
Any tips on what I can try to correct this problem.
Ian

Renaming PPT picture using VBA Macro Excel

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?

Copy a sheet from another open workbook into current workbook

I'm trying to write a macro that takes Sheet1 from another, already open, workbook and copy it into a the workbook that will use the data. The macro will be run from the workbook that will be receiving the copied sheet and the file I want the data from will always be named the same.
I've tried the follow code, but it either just copies incorrectly or doesn't work.
Workbooks("FileIWantToCopyFrom.XLSX").Sheets("Sheet1").Copy
ActiveWorkbook.Worksheets("FileIWantToCopyFrom.XLSX").Select
Sheets("Sheet1").Copy After:=Workbooks("Book1").Sheets(1)
Any help would be much appreciated. Thanks!

excel 2010 Paste Link radio button disabled with chart object

I've created a chart in a workbook. I want to copy and paste that chart into another workbook in such a way so that when I update the original data it automatically updates both charts.
Between Excel and Word there are no problems: I can paste the chart as link (see below):
but in Excel the same option seems to be disabled:
Any idea to solve my problem? The chart copied in the destination only updates if the original file is open, and the data changed!
Many thanks in advance.
I've not done this much, but when I have I generally just paste (i.e. Ctrl+C). The chart series should be automatically updated to refer to the source workbook, the relevant worksheet within that workbook, and keep the cell ranges the same.
So my thought would be that the option isn't disabled, it's just implicitly built in to the normal paste. Which would make sense; The use-case for keeping the same source range of cells, but on the new worksheet being pasted to (even inside the same workbook, let alone in a different workbook) is not exactly one that seems crazy useful.

Error 1004: Microsoft Excel cannot paste the data

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.

Resources