I use this to copy a chart to clipboard: ChartArea.Copy.
But now we wanna copy two charts at the same time to the clipboard. Is that possible?
Printable View
I use this to copy a chart to clipboard: ChartArea.Copy.
But now we wanna copy two charts at the same time to the clipboard. Is that possible?
no, you would have to do it by combining the chart areas if that can be done as it can with ranges
else, can you set the copy destination then just copy the 2 areas
Pete,
Can u show me what you mean...
i have never tried with chart areas, but to combine 2 (or more) ranges, use union
vb Code:
set myrange = union(range("A4:J19"),range("L12:X99")) myrange.copy
Thanks Pete,
But if you do this manually, you select the first chart then hold down Ctrl buttom and select the second chart. Then you can copy and paste two charts. Can't I do this in VB?
i am sure you can if you can do manually, the chart area should just be another range as i posted above
i try to never use select when i write code as i can have problems, especially from outside programs, so would combine without selecting, then copy
Ok, I will try that,
But If I wanna copy (with VB) two charts inside two OLE (OLE, OLE2) objects the union function doesen't work. Have you any suggestion how I should do?
Copy one chart I do like this
VB Code:
Dim objGraph As Object Clipboard.Clear Set objGraph = Me.OLE1.object objGraph.ChartArea.Copy
someone?
When I record a macro in excel and then copy two Object charts it looks like this:
But how can I do this from VB. I have two OLE with MsGraph in each one of them.VB Code:
ActiveSheet.Shapes.Range(Array("Object 2", "Object 1")).Copy
Copy a chart from one OLE is no problem. But how can I copy both charts at the same time to clipboard?
Copy one chart I do like this
VB Code:
Dim objGraph As Object Clipboard.Clear Set objGraph = Me.OLE1.object objGraph.ChartArea.Copy Set objGraph = Nothing
i believe that is like trying to work in 2 instances of excel, so i don't believe you would be able to do it, the only way i can think of is to copy the first, paste it before of after the second, then copy both, or use a temporary workspace to copy both to, before copying together
Ok, use a temporary workspace to copy both to is a good ide. But as usual, how should I do that in VB? Do you have any examples?
use an empty sheet in one of your workbooks?
add a new sheet if need be delete when finished
Ok, but I not use excel. All this is in VB...
yes, but you already have workbooks open that you can work with
a range is copied as a string, so it can just be returned into a string variable, but if you want to position one range against another or anything like that then putting it into another sheet makes sense, but if you ara happy to just have one followed by the second then you could just add both to string variables and manipulate the strings
Ok, I understand.
Do you have any complete example how I should do?
try like this
as you are selecting the source by code, you will not need to use separate subs to combinevb Code:
Dim strtxt As String ' delcare as global at top of form or module Private Sub Command1_Click() 'get 1st clipboard object strtxt = Clipboard.GetText End Sub Private Sub Command2_Click() 'get 2nd clipboard object strtxt = strtxt & vbNewLine & Clipboard.GetText Clipboard.SetText = strtxt ' copy combined to clipboard End Sub
Hi again Pete,
I can't get it to work. If I do like this it only paste the laste copied chart? Why?
VB Code:
Private Sub cmdCopyCharts() Dim strtxt As String Dim objChart1 As Object Dim ObjChart2 As Object Clipboard.Clear Set objChart1 = Me.OLE1.object Set ObjChart2 = Me.OLE2.object objChart1.ChartArea.Copy strtxt = Clipboard.GetText ObjChart2.ChartArea.Copy strtxt = strtxt & vbCrLf & Clipboard.GetText Clipboard.SetText strtxt Set objChart1 = Nothing Set ObjChart2 = Nothing End Sub
you want to post a demo project? to test with
Ok, check this...
i tried this and it basically works, but you will have to do some adjustments to the picture box sizes, to get the image the way you want it
you will need 3 pictureboxes, though you could probably use stdpictures for 2
vb Code:
Set objChart1 = Me.OLE1.object Set ObjChart2 = Me.OLE2.object objChart1.chartarea.Copy Picture2.Picture = Clipboard.GetData ObjChart2.chartarea.Copy Picture3.Picture = Clipboard.GetData Clipboard.Clear Picture1.AutoRedraw = True Picture1.PaintPicture Picture2.Picture, 0, 0 Picture1.PaintPicture Picture3.Picture, 0, Picture2.Height Picture1.Refresh Picture1.Picture = Picture1.Image Clipboard.SetData Picture1.Picture
Thanks again Pete!
Now it almost works for me. But I have problems with the sizes. Can you upload your working sample also?
i didn't try to get the sizes right, but you can try setting autosize to true for all the pictureboxes, all the pictureboxes could be set to visible to false, a you don't need to see them
Ok, but I only still get the last copied chart to the clipboard. Not both when i do a paste? Why?
Pete,
Can you upload your working project here?
i don't know that i kept it, i will have to redo a bit later
(close, don't save)
here it is, works perfectly............... lol
only 2 pictureboxes required, picture2 needs autosize
Thanks Pete!