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.
Related
I need to create a new sheet in a xlsm file that's a copy from another sheet from that same xlsm.
That's kinda easy but the problem's that when I copy it, it won't copy the formatation and macros as well.
And they're the main reason I want to copy it.
Original Sheet
I've tryed the following:
import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
excel.Visible = True
book = excel.Workbooks.Open(r"C:\Users\lbsme\Desktop\reprogramacao\modelo.xlsm", UpdateLinks=0)
model = excel.Worksheets('model')
sheet1 = book.Worksheets.Add()
sheet1.Name = 'Copy'
sheet1 = book.Worksheets('Copy')
model.Range("A1:CF128").Copy()
sheet1.Paste(sheet1.Range('A1'))
And it works... kind of...
It does copy the formulas and part of the formatation but it does not copy the whole formatations or the buttons.
Copied
Also, while copying, it shows the same error messenge over and over again and I have no idea why since there's no other sheets besides the ones shown.
Even if I click "yes to all" it will show the messenge again and again.
I click it about eleven times.
Error
I need my copies to be exatly like the model, including the buttons.
How to copy or duplicate the whole sheet perfectly?
This simple code copies the whole sheet
Sheets("mysheet").Copy After:=Sheets("myothersheet")
Either way I guess you already know that you can just right-click on the sheet tab and then click on "Move or copy"
I don't see the point on copying the macros if it's in the same workbook....
If you want to copy paste the macros' code to modify one of them you could just copy-paste it or if it's really something that you do regularly enough and it's repetitive you could just use a python library to write macros or... I found this to duplicate vba code directly from excel:
https://support.google.com/docs/thread/3126412/how-can-i-create-a-script-or-macro-to-duplicate-and-rename-a-tab-for-each-day-in-a-month?hl=en
If this was helpful please set this as the proper answer! :)
Have a nice one!
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?
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'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.
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...