Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel 2007 from vba Access: name and select a chart 1

Status
Not open for further replies.

aldi07

MIS
Jun 22, 2010
100
0
0
CA
Hi, I am trying to rename a chart in excel 2007 from vba access 2007, then access that chart from access 2007.
This is the code I am using:

With xlObj
.ActiveChart.Parent.Name = MyReportNo
 
Sorry, I posted by hitting the wrong key. Here is the entire question:
Hi, I am trying to rename a chart in excel 2007 from vba access 2007, select a new location on the spreadsheet, then access that chart from access 2007 to place it in the new cell.
This is the code I am using:

With xlObj
.ActiveChart.Parent.Name = MyNewChartName
.Range(MyTargetChartPos).Select
.ActiveSheet.ChartObjects(MyNewChartName).Select
.Selection.Cut
.ActiveSheet.Paste
End With

When it reaches .ActiveSheet.ChartObjects(MyNewChartName).Select I get the error "Application-defined or object-defined error.

Could anybody tell me what I am doing wrong? (remember it is office 2007).

Thank you
 

Code:
'NEVER NEVER NEVER assume that the activeANYTHING will be what you expect!
'Explicitly reference all objects as a practice.
'assuming that xlObj is the Excel Application object
With xlObj.Sheets("Sheet Name Where Chart is")
'assuming that the first chartobject is the correct one...
    .ChartObjects(1).Name = MyNewChartName
    .ChartObjects(MyNewChartName).Cut
    .ActiveSheet.Paste
End With

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
SkipVought, thank you for your answer. You are quite right. Problem resolved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top