Can not get Excel macros to save chart format -lost in space!

Help??? I've been searching this forum for 5 days trying to find a problem 
similar to what I am having without any luck.

I have been trying to use Excel macro to record the creation, formating and 
saving of a simple bar chart against my Excel data range but the macros do 
not run for the chart. I am able to creat the charts okay but the macro craps 
out when I run it.
I keep getting " Set ActiveChart = ActiveSheet.ChartObjects(Chart1)"
type errors as if it's not recognizing the chart that I just made.

I am an advanced Excel person BUT not so with VB coding. 

All I am doing is selecting a data range, inserting a chart, selecting a new 
chart type, editing the chart label and then formating it to fit the page.

I'm pulling my hair out! :((( I hope someone can help me?
Thanks!
0
Utf
3/18/2010 7:07:01 PM
excel.charting 18370 articles. 0 followers. Follow

5 Replies
1253 Views

Similar Articles

[PageSpeed] 39

AccessQuestion  -

Excel VBA Help says "Use ChartObjects(index), where index is the embedded 
chart index number or name, to return a single object."

So, maybe ChartObjects("Chart1") would work if you have named the chart 
"Chart1," or maybe ChartObjects(1) would work if its the first chart.

I recommend Jon Peltier's web site for chart information. For your task, the 
following page may be useful:

http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html

-  Mike
http://www.MikeMiddleton.com


"AccessQuestion" <AccessQuestion@discussions.microsoft.com> wrote in message 
news:DE831851-9CDB-4112-A870-BC569E46AF66@microsoft.com...
Help??? I've been searching this forum for 5 days trying to find a problem
similar to what I am having without any luck.

I have been trying to use Excel macro to record the creation, formating and
saving of a simple bar chart against my Excel data range but the macros do
not run for the chart. I am able to creat the charts okay but the macro 
craps
out when I run it.
I keep getting " Set ActiveChart = ActiveSheet.ChartObjects(Chart1)"
type errors as if it's not recognizing the chart that I just made.

I am an advanced Excel person BUT not so with VB coding.

All I am doing is selecting a data range, inserting a chart, selecting a new
chart type, editing the chart label and then formating it to fit the page.

I'm pulling my hair out! :((( I hope someone can help me?
Thanks! 

0
Mike
3/18/2010 9:42:58 PM
Thanks Mike for the help! Yes I did try those names as well but
still get the same problem. I will check out Jon's website.

-- 
mfg2529


"Mike Middleton" wrote:

> AccessQuestion  -
> 
> Excel VBA Help says "Use ChartObjects(index), where index is the embedded 
> chart index number or name, to return a single object."
> 
> So, maybe ChartObjects("Chart1") would work if you have named the chart 
> "Chart1," or maybe ChartObjects(1) would work if its the first chart.
> 
> I recommend Jon Peltier's web site for chart information. For your task, the 
> following page may be useful:
> 
> http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html
> 
> -  Mike
> http://www.MikeMiddleton.com
> 
> 
> "AccessQuestion" <AccessQuestion@discussions.microsoft.com> wrote in message 
> news:DE831851-9CDB-4112-A870-BC569E46AF66@microsoft.com...
> Help??? I've been searching this forum for 5 days trying to find a problem
> similar to what I am having without any luck.
> 
> I have been trying to use Excel macro to record the creation, formating and
> saving of a simple bar chart against my Excel data range but the macros do
> not run for the chart. I am able to creat the charts okay but the macro 
> craps
> out when I run it.
> I keep getting " Set ActiveChart = ActiveSheet.ChartObjects(Chart1)"
> type errors as if it's not recognizing the chart that I just made.
> 
> I am an advanced Excel person BUT not so with VB coding.
> 
> All I am doing is selecting a data range, inserting a chart, selecting a new
> chart type, editing the chart label and then formating it to fit the page.
> 
> I'm pulling my hair out! :((( I hope someone can help me?
> Thanks! 
> 
> .
> 
0
Utf
3/19/2010 4:46:01 AM
Hi,

There is a difference in VBA between a Chart and a ChartObject. The latter 
is a sort of container for a Chart and can be embedded in a Worksheet.

ActiveChart is a property of the ChartObject and is read-only.
You can't write something like Set ActiveChart = MyObject.

To use the Chart name instead of the index, find out what the chart name is 
(Ctrl-Click on the embedded chart and read the name of the Chart Object at 
the top left). Then enclose it in double-quotes in your code. Usually 
something like
..ChartObjects("Chart 1") not .ChartObjects(Chart1)

Try running this bit of code to understand what is going on;

Option Explicit        ' good idea to always put this before any of your 
code

Sub tst()
Dim cht As Chart
Dim oCht As ChartObject

Set oCht = ActiveSheet.ChartObjects("Chart 1")
Set cht = ActiveSheet.ChartObjects("Chart 1").Chart

Debug.Print oCht.Name, cht.Name

' you can activate the ChartObject , you can't activate the chart
oCht.Activate

End Sub

Ed Ferrero
www.edferrero.com 


0
Ed
3/19/2010 7:08:45 AM
Thank you very much Ed! I will try out what you mean as well.

-- 
mfg2529


"Ed Ferrero" wrote:

> Hi,
> 
> There is a difference in VBA between a Chart and a ChartObject. The latter 
> is a sort of container for a Chart and can be embedded in a Worksheet.
> 
> ActiveChart is a property of the ChartObject and is read-only.
> You can't write something like Set ActiveChart = MyObject.
> 
> To use the Chart name instead of the index, find out what the chart name is 
> (Ctrl-Click on the embedded chart and read the name of the Chart Object at 
> the top left). Then enclose it in double-quotes in your code. Usually 
> something like
> ..ChartObjects("Chart 1") not .ChartObjects(Chart1)
> 
> Try running this bit of code to understand what is going on;
> 
> Option Explicit        ' good idea to always put this before any of your 
> code
> 
> Sub tst()
> Dim cht As Chart
> Dim oCht As ChartObject
> 
> Set oCht = ActiveSheet.ChartObjects("Chart 1")
> Set cht = ActiveSheet.ChartObjects("Chart 1").Chart
> 
> Debug.Print oCht.Name, cht.Name
> 
> ' you can activate the ChartObject , you can't activate the chart
> oCht.Activate
> 
> End Sub
> 
> Ed Ferrero
> www.edferrero.com 
> 
> 
> .
> 
0
Utf
3/19/2010 2:06:03 PM
Hi Mike and Ed,
Sorry for my slowness here :(( thank you for your help and patience!
I'm still having problems :((( I feel really stupid here.
Basically I have 2 macros, 806X and 807X.

Macro806X just creates a simple bar chart for me. Macro806X works 
fine all the time.  Macro807X is the 2nd macro after I  run 806X. This macro 
simply just takes the chart that macro806X created and formats it.

I've listed the code for both macros below.
Also, I can't seem to find the name of the chart by doing CTL+click on the 
chart (which is its own worksheet). Not sure what I'm doing wrong. 

Sub Macro806X()
'
' Macro806X Macro
'
    Cells.Select
    Range("A1:AA40").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range( _
        "'Query18_Subtotal 13wk qty cross'!$1:$1048576")
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.PlotArea.Select
    ActiveChart.SetSourceData Source:=ActiveSheet.Range("A1:R30"), _
     PlotBy:=xlRows
     
    ActiveSheet.ChartObjects(1).Activate
    ActiveChart.ChartArea.Select
    ActiveChart.Location Where:=xlLocationAsNewSheet
    ActiveChart.ApplyLayout (5)
    ActiveWorkbook.Save
End Sub


Sub Macro807X()
'
' Macro807X Macro
'
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Select
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Text = "13 Week By Qtry"
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartArea.Select
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Select
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Text = "13 Week By Qty"
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartArea.Select
End Sub

0
Utf
3/19/2010 2:38:12 PM
Reply:

Similar Artilces:

Problem with "Use Unicode Format when saving messages"
In outlook we have option to set "use Unicode format when saving messages"(outlook>tools>options>other >Advanced options),even though option is enabled, when ever I try "save as" the email into folder, it is showing Html format by default.However can drop down the list and select the Unicode format. But I need Unicode message format to be shown by default if I need to "save as" any email. Any Suggestion ? Regards, Sam That is not possible and that is not what this option controls. The option controls whether the default safe fo...

Excel button problem
Hi All I have a macro that copies a worksheet in the active workbook and puts it into a new workbook - then formats it and deletes any buttons on the worksheet. On the first click on the button the macro works ok. On the second click, it fails because the all assigned macros on all buttons in the active workbook changed from "mba" to "book1!mba". Book 1 doesn't exists (wasn't opened, wasn't saved, doesn't have the macros). I've never experienced this problem before?? Can anyone help to solve this problem? FYI The macro to do this is c...

Excel 97 #9
Please can anyone help??? I have two columns in Excel 97. The first contains a list of statu values eg. pending, or granted or withdrawn. The second contains date eg.01/12/1997, 05/06/2003. I woudl like to know how to get all th granted apps before 31/12/2003. Can anyone help please -- Message posted from http://www.ExcelForum.com theres many ways, but an easiest way would be to do a sort. Highlight the 2 columns, click on data, then sort, then sort by status, then by date. this should group them all together. hope this helps...toe >-----Original Message----- >Please can anyo...

Unable to Save in Publisher 2000 to Flash Drive
I work in a school district and one of our teachers uses Flash Drives/Memory Keys (whatever you want to call them) for her students to save their projets on. She's starting a unit on Microsoft Publisher and had the students open a template off the flash drive and change it and resave in a folder on the flash drive but all the students are getting the following error: "There is no disk in the floppy drive or the drive door is not closed. Please make sure that the floppy drive is ready, then try again." -It is not a permissions issue - even the teacher is unable to save to...

conditional formatting sort
Is there a way to sort after conditional formatting. So, if I've set up a conditional format to color my text red if the number is between 0 and 95, then I want to sort so all red numbers are at the top of the spreadsheet? Any ideas? Thanks for your time and assistance. Roberta On Thu, 25 Oct 2007 05:08:00 -0700, rrupp <rrupp@discussions.microsoft.com> wrote: You can't sort by color, but you can add a column to your query like this: SortColumn: Iif(SomeValue >= 0 and SomeValue <= 95, 1, 2) Then sort by this column. -Tom. >Is there a way to sort after condition...

New to excel
Hi All, I'm new to Excel ( and to this forum :) ) and so I hope somebody may b able to help me. I've got 2 questions.... QUESTION 1 I've got a spreadsheet which takes data from one worksheet and uses i to calculate data in a second worksheet using the following code formula: =IF('4th November 2005'!B19="","nothing here dude",IF(B19<'4th Novembe 2005'!B19,"UP",IF(B19='4th November 2005'!B19,"Same",IF(B19>'4t November 2005'!B19,"DOWN")))) The problem is, when I create a new worksheet I have...

Looking for Excel Help
I'm a very novice Excel user and am looking for a little help with creating a formula for a spreadsheet I'm creating for my personal use. I would appreciate some assistance if possible. Thanks in advance. Dan --- Message posted from http://www.ExcelForum.com/ Hi Dan! Post a sample of what you want to do. Your question is just a tad open ended <g> -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. "DanB4105" <DanB4105.ywtpa@excelfor...

POST or GET?
(apologies if this is OT but I couldn't find an HTTP newsgroup) I am writing an MFC client application which speaks to an HTTP server. The server will send text data to the client, the client will modify and return that data to the server along with a small amount of new data. Should I use GET or POST to get the data from the server? "Richard" <richard@hello.com> wrote in message news:zWudf.14758$Cq4.8824@newsfe7-gui.ntli.net... > I am writing an MFC client application which speaks to an HTTP server. The > server will send text data to the client, the client...

Cannot open Outlook, keep getting Send error report of Microsoft.
We are having problems with Outlook 2003. Everytime we try to open, we get this: Send error report to Microsoft. Any ideas why? All windows and office update have been completed. ...

Savings a/c cashflow doesn't show withdrawals
Money 2003 When I do a cashflow forecast for my savings a/c it doesn't take into account transfers to my "cash" account - the one I use to keep track of what I spend my cash on. Consequently when I do the cashflow it gives an unreal projection of savings. I wish I could save $3000 in 2 months but it's not going to happen... ...

Excel corrupts when asking to update vlookups
We are experiencing weird behavior with some Office 2K3 Excel spreadsheets that contain lots of calculations, but no macros. On some pc’s Excel acts normally, on others you get the error. I have a couple of screen shots available. Any help is appreciated. If desired, send your file to my address below. I will only look if: 1. You send a copy of this message on an inserted sheet 2. You give me the newsgroup and the subject line 3. You send a clear explanation of what you want 4. You send before/after examples and expected results. -- Don Gu...

Uninstall of mappoint has caused errors with excel
Hi, I am running Office 2003 on the terminal server (windows 2003) and had a copy of mappoint as well. This is a mapping program. We ininstalled mappoint which has caused an error message with Excel and other office products. The error says "Cd:\documents and settings\administrator.ocrdc1\application data\microsoft\addins c:\Program files\common files\microsoft shared\geography\mpoai9.dll is not a valid add-in." I then click OK and excel opens up and everything is fine. The problem is that we are using other programs as well such as Quickbooks that export to excel and t...

Is anyone an expert with outlook that I can call on the phone?
How do I share calenders between outlook and my MSN Premier account? Assuming you are using the outlook connector, you need to set the msn account to be the default message store then outlook will use the msn calendar as the default. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: mailto:EMO-NEWSLETTER-SUBSCRIBE-REQUEST@PEACH.EASE.LSOFT.COM You can access this...

I need a macro
I would like a macro to do the following: I would place the the cursor in any cell and this macro would give me the average of all the entries to the left if the selected cell. EX: I place the cursor in cell M12. I want this macro on display in cell M12 the average of all the values from Col C12 to Col L12. Note that there may NOT be entries in all the cells in that range. Also the start point would always be col C .Thanks You can do this easily with a worksheet_selection event in the sheet module but you would probably want to restrict to a certain range or columns and rows or it woul...

How do I Remove a Split from my Comments in Excel 2003? #2
I have set my current workbook to split/freeze the first column and first 2 rows. Now, when I add a comment to the second row (in any column) my comments are cut off if I should scroll down. I don't ever remember the behavior before. And I don't know what I've done to enable it but it's really annoying. How do turn this off ? ...

get a result of an sql into a field
Hi there I would like to get a result of an sql execution (ms sql server) into aq filed. example i A1 I have a ID number in A2 I would like to get the result of something like this 'select name from address where id=A1' Does this exist in Excel ? Thanks in advance Ralf Here is the sub i have written for loading an Sql Query into th worksheet. Parameters: Server Name DataBase Name SQL Command Target Sheet name Column to begin from Row to begin from ex: CALL LoadData("MyServer","MyDataBase","Select UserName fro TblNames", "QueryData"...

unable to paste Excel 2003 chart into Outlook 2003
(This was posted on "excel.charting" group.) I have a user who's unable to paste an Excel 2003 chart into Outlook 2003 email message. In Outlook options, the checkbox is selected for "Use Microsoft Office Word 2003 to edit e-mail messages". When I tested this on my own computer running the same version of Office, if the box is check, I have no problem pasting; if this box is cleared, I cannot paste. But on his computer, it doesn't work regardless. Thanks and regards, TL ...

learning Excel #3
Hi, I was considering learning Excel as an additional tool for my data analysis work. Is it better to use data sets that I have previously used with SPSS and apply the same analysis tools as in SPSS? For applying the appropriate tools, I was considering using excel's online help. The second option I have is to use some excel book for data analysis and apply the techniques to data sets provided with the book. Any suggestions????? regards Metal ...

Can't do adjustment in analytical accounting
I am trying to change an analytical assignmnet through the Edit Analysis. When I try and change it, I receive an error stating "The Code of this Transaction Dimension cannot be adjusted". Has anyone seen this before? I have done similar changes many times, but I don't know why I can't now. Any insight would be helpful. Thanks, KJ Hi KJ What version of Gp are you running? I haveseen this happen in 8 but one of the service packs fixed it. (I think it was SP 4 or 5) Fliehigh "KJ" wrote: > I am trying to change an analytical assignmnet through the Edit >...

How do you invoke the Let and Get class Functions
I have create classes with the Let and Get functions and now I would like to use these functions to store and retrieve data in the class which will then be put into a collection. Here is the class functions: Private pBusPart As Double Private pStartTime As Date Private pIndex As Integer '''''''''''''''''''''' ' BusPart property '''''''''''''''''''''' Public Property Get BusPart() As Double BusPar...

Can I share entities in migration process?
The entities in CRM have only one owning user. If I want=20 who a user see a entity of another user, the entity must=20 be shared with this user.=20 Well, I want migrate entities who must be shared with some=20 users. Exists a way to do it? Thank you for pay attention and sorry my bad english. []'s Vin=EDcius Pitta Lima de Ara=FAjo ...

number format with leading 0
Dose anyone know how to create a number format that would show a leading zero for the numbers 0-9. That is, so that 1 would show as 01. I can do with a text format but would like to retain the integrity of the number. Thanks Try this: Format>Cells>Number Category: Custom Type: 00 Click [OK] Does that help? *********** Regards, Ron "Darby" wrote: > Dose anyone know how to create a number format that would show a leading zero > for the numbers 0-9. That is, so that 1 would show as 01. I can do with a > text format but would like to retain the integrity...

How to get to email from Word
Sorry to break the thread, but replying to the original thread now produces an error message :( The suggested changes don't make any difference to the essential premise that it all works as long as Outlook is running in the background. Stepping though the code has provided inconsistent results. It usually crashes at the line strEMail = Application.GetAddress("", strEMail, False, 1, , , True, True) when the address is selected from the dialog and you OK out of the dialog; but I have noticed that this call has produced crashes in other routines where Outlook is not running. Th...

Save as .doc
In Outlook 2003 there is no option to save an eemail as .doc. is there setting that can be turned on to allow this? REBeyer wrote: > In Outlook 2003 there is no option to save an eemail as .doc. > is there setting that can be turned on to allow this? Not that I know of. You can save as .txt, open in Word, and save as a Word doc, though. "Lanwench [MVP - Exchange]" wrote: > REBeyer wrote: > > In Outlook 2003 there is no option to save an eemail as .doc. > > is there setting that can be turned on to allow this? > > Not that I know of. You can save as ...

I cannot get Outlook to send/receive. Error says object not found
I just installed Outlook2007. I cannot get the send/receive to work. That is when the error says Object not found. If I go to accounts and properties, I run the two tests and they complete fine. What should I try next? Outlook 2007 is the only new program, all the rest are from Office 2003 IMK <IMK@discussions.microsoft.com> wrote: > I just installed Outlook2007. I cannot get the send/receive to work. > That is when the error says Object not found. If I go to accounts and > properties, I run the two tests and they complete fine. What should I > try next? Outlook 2007 is ...