I suspect that the reason is that you have the chart activated and this itself doesn't contain the range.
Maybe try ActiveChart.parent.parent.parent.range(...
I suspect that the reason is that you have the chart activated and this itself doesn't contain the range.
Maybe try ActiveChart.parent.parent.parent.range(...
Martin
interesting idea. I'll try that out now![]()
That didn't work, unfortunatelybut I think I've nearly got it. I added in the variable "ws".
I don't know much about VBA but it's crashing here because I say "ActiveSheet" when the sheet isn't yet active, I suspect. I don't know enough about VBA to be sure. How can I say something like:![]()
Private Sub Workbook_Open() Dim ws As Worksheet Set ws = ActiveSheet Dim n n = ActiveSheet.ChartObjects.Count For i = n To 1 Step -1 ActiveSheet.ChartObjects(i).Delete Next i ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=ws.Range("[energyOutput.csv]energyOutput!$A") ActiveChart.ChartType = xlLine End Sub
but without getting a type mismatch? There must be some way to specify the sheet name. I think that would make it work. I have a good feeling about that one.![]()
Set ws = "worksheet1"
Just so I'm sure, is this a sheet?:
http://img150.imageshack.us/my.php?image=sheet1qc1.jpg
I hope I'm not barking at the wrong bush.
Thanks for the reply![]()
Try
![]()
Set ws = ThisWorkbook.ActiveSheet
Thanks again
I tried that and got this error:
http://img521.imageshack.us/my.php?image=errorlc6.jpg
This should be so simple but I can't seem to get it. There must be something terribly obvious that I'm overlooking. I've uploaded the file, if you want to have a look:
http://www.geocities.com/mtwstorage/energyBooks.zip
Any ideas where I'm going wrong?
The following code gets you as a graph although it might not be quite the graph that you are expecting. Adjust the Open line to the appropriate path.
![]()
Private Sub Workbook_Open() Dim ws As Worksheet Set ws = ThisWorkbook.ActiveSheet Workbooks.Open "c:\energyOutput.csv" Dim n ThisWorkbook.Activate For i = ActiveSheet.ChartObjects.Count To 1 Step -1 ActiveSheet.ChartObjects(i).Delete Next i ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Workbooks("energyOutput.csv").Sheets("energyOutput").Range("$A1:$C" & Workbooks("energyOutput.csv").Sheets("energyOutput").Cells(65536, 1).End(xlUp).Row) ActiveChart.ChartType = xlLine End Sub
Martin, that's absolutely perfect. Thank you so much. Sending lots of virtual kisses your way xxxxxxxxxxxxx :D
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks