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
1105 Views

Similar Articles

[PageSpeed] 16

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:

Formatting a single grid line
Don't laugh but I was wondering if there was a back door way of bolding up a single horizontal gridline to make it stand out from the rest. My alternative is to draw a line on the chart but then I need to adjust it if my scale changes. Thanks much, Reney Hi Reney, Unfortunately you can only format all of the gridlines at once. Have a look at these examples for adding a line to a chart. http://peltiertech.com/Excel/Charts/AddLine.html http://tushar-mehta.com/excel/charts/straight_lines/index.html http://www.andypope.info/charts/averageline.htm Cheers Andy Reney Langlois wrote:...

Can't see 401(k) contribiltion total
I've set up a 401(k)accont. I transfer contribiltions to this 401(k)account from each paycheck. When I go to the 401 (k) account view, it shows all the informations such as transections and the account vallue ect., EXCEPT the total contribiltion. I want to know not only what my 401(k) vallue is, but how much money I have contribilt total or over a period of time as well. I find no place to see it. Anybody can help? I'm using Money2002 and 2004 Trial Verstion. Thanks a lot! ...

How can I print a selection in Outlook 2003?
How can I print just a selection of an email in Outlook 2003? The printer driver window is different from the one that comes up in Outlook Express. Thank you! You can do this for HTML formatted messages. Highlight your text, File-> Print... and select to print only the selection -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Murphie" <Murphie@discussions.microsoft.com> wrote in message news:92F39B50-B877-408A-AAA7-DF350B1D72ED@microsoft.com....

error: OBE-15502 Can only have 16000 per document
Hi, I tried to export data from oracle query builder to Excel sheet, got a error message: OBE-15502 Can only have 16000 per document Is there any way i can get more records(over 16000 or unlimited) in one sheet? thanks. -- JJ ...

Can different editions of Publisher be used together?
If my son uses Publisher 2003 on a school computer, downloads his work to a flash drive, brings it home to edit on Publisher 2007, will he then be able to take the edited work back to the school computer to be used, or will it not be compatible? Stateparent wrote: > If my son uses Publisher 2003 on a school computer, downloads his work to a > flash drive, brings it home to edit on Publisher 2007, will he then be able > to take the edited work back to the school computer to be used, or will it > not be compatible? Publisher 2003 and 2007 share a common file format, so the sc...

Can't send/receive
anyone have a situation where all of sudden they can't send new messages or receive anything? I get a message when I click on "accounts" that says 'fatal error in outlook unable to complete operation" ...

Show format in formula bar
Hello: On some spreadsheets I have #'s in the billions added together in cells. Sometimes it is difficult to verify the number is 10,000,000,000 because it shows up as 10000000000. My eyes get crossed counting the zeros. I'd love if the formula bar would show 10,000,000,000; however, can't seem to find a way to do this. Is this possible? No, you can't change the number formatting in the formula bar. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Native" <native_texan_03@yahoo.com> wrote in message n...

Can not Customize Leads View
Hi I have tried to customize the Leads view, I tried to add a view and add some columns to it. The view is shown however I see only the name column. When I go back to the View customization, I see the columns I added. Published your customizations??? -- ---------------------- regards, Ilya Milshtein MBS Master, MBSCP, MCP Softline International www.softline.ru "alsap" wrote: > Hi I have tried to customize the Leads view, I tried to add a view and add > some columns to it. > The view is shown however I see only the name column. > When I go back to the View customi...

need to chart sum of 2 rows in worksheet
I have a worksheet in which I have 12 columns to represent the months and my expense categories in the rows below. The last row is a Total row of all the expenses above it. One of the values I want to represent in a 12-month line graph is the Total row less the Misc Expense row. How can I graph this without creating a new row in my worksheet to hold just this calculated value? I'm very comfortable with writing macros if that's what it will take to accomplish this. Thanks, Barry ...

Can I change the "Applied Task Update Requests and Errors" view?
I really like this view in PWA 2007, but I would like to replace one column with another. Is this view customizeable? Randy -- Bad news, my friend. This view is not customizable, nor is the view shown in the Task Updates customizable (which many users wish it was). Hope this help. -- Dale A. Howard [MVP] VP of Educational Services msProjectExperts http://www.msprojectexperts.com http://www.projectserverexperts.com "We write the books on Project Server" "Randy Schmid" <RandySchmid@discussions.microsoft.com> wrote in message news:72FA34B5-...

Should be an easy but I can not figure it out!!
I have a text box where the user enters a date and it is assigned to variable txtDate. How to I convert that to the serial number of the date? Thanks for the help IIRC, you can use DATEVAL(String) to get the serial date. -- HTH, Barb Reinhardt "VinceW" wrote: > I have a text box where the user enters a date and it is assigned to variable > txtDate. How to I convert that to the serial number of the date? > > Thanks for the help Barb, Thanks for the quick reply, however I get the error "Sub or Function not defined" when trying...

Bulk attachments
I have a very long list of Images in a single folder that I want to attach to seperate fields in a table/form. Each record contains two images, which are named like this: W:\Foldername\Micromap Run 001 A.bmp =(1st record) W:\Foldername\Micromap Run 001 B.bmp =(1st record) W:\Foldername\Micromap Run 002 A.bmp =(2nd record) W:\Foldername\Micromap Run 002 B.bmp =(2nd record) W:\Foldername\Micromap Run 003 A.bmp =(3rd record) W:\Foldername\Micromap Run 003 B.bmp =(3rd record) and so on... Image A goes to field A Image B goes to field B Is there a way of doing this au...

Excel's calculations are off a few cents!
I can't figure out why my TOTAL for $ column is off from 1-5 cents. When I check the amounts going across, they are correct, but the amount at the bottom of the column is off!! What am I doing wrong? Any help would be greatly appreciated, as I have to manually check all Excel's figures. View more decimal places Natalie, does it still add up incorrectly?? I'm guessing your summing calculated values, that are viewed at less precision than calculated. You can use ROUND(formula, #decimals) to make the calculations round to the precision you desire, or you can set "Tools&q...

can't uninstall exchange from cluster nodes
hi our client has several exchange clusters, and one of them is being retired. we have removed the exchange resources and the EVS and the server no longer appears in the organization and everything else there seems to be ok. we can't seem to uninstall exchange from either of the nodes. setup will start saying it's loading components then terminates with no error; happens on both nodes. both nodes are exchange 2003 sp1 on windows 2003. i did find the setup log; here is what it says, hope someone can shed some light on this (company info replaced with < >): [19:47:23] *...

CListCtrl
Hi, Does anybody know an easy of removing the black vertical tracking line that appears while resizing columns? I've been trying to prevent it through HDN_ENDTRACK / HDN_TRACK, but I wasn't successfull. Is there a specific flag that I can set to disable it instead? Thanks in advance for your time, Best regards, -Onur I can't imagine why you'd want to do that, but here's my suggestion: Override the CListrCtrl and CHeaderCtrl class, and have your listview control use your derived header control. In the header control class, handle the WM_SETCURSOR message and load a d...

Can't delete email #2
I'm am trying to help a friend who is using Outlook Express on W98, I cannot delete any messages from her in box. She has over 500 in there, which may be part of the problem. Any suggestions? Desperate! Mark Mark Ryan <m.ryan@earthlink.com> wrote: > I'm am trying to help a friend who is using Outlook Express > on W98, I cannot delete any messages from her in box. She > has over 500 in there, which may be part of the problem. > Any suggestions? The first suggestion is to ask in an Outlok Express newsgroup. The second suggestion is to delete Deleted Items.dbx and ...

Can Not Reply To Emails
Running Windows 7 Professional with latest version of WLM. I get email messages I can not reply to. The reply button is grayed out. For now I am forwarding them to my WinXP computer and then replying from that computer with OE6. Anybody have any ideas? -- <Bill> Brought to you from Anchorage, Alaska. The most obvious reason for not having an active Reply button is not having a mail account set up. --=20 Gary VanderMolen, Microsoft MVP (Mail) http://mvp.support.microsoft.com/default.aspx/profile/vandermolen "Bill Bradshaw" <bradshaw@gci.net>...

How can I rename a database table?
Hi I am working on a project that uses the MFC CDatabase and CRecordset classes to handle its interfacing with an Access database. It is necessary for the software to rename a table within existing user databases to ensure that they are valid for use with the new version of the software. As a result of my limited database and MFC knowledge I am having difficulty finding a way of renaming the table. I have tried using the following: try { theDataBase.ExecuteSQL( "RENAME oldTableName TO newTableName"); } catch( CDBException* e) { e->m_strError; } However, it results in th...

Chart line is discontinuous
Hello, A similar problem to my last. I have entered data from reading sheets and not every date/time has a data point. I have noticed that if there is no date/time the chart does not draw the line between data points. Please help me out with this. You can set your chart options (Tools, Options, Chart tab) to treat empty cells as not plotted (leave gaps) zero or interpolated. -- Steve "Lady Excel" <LadyExcel@discussions.microsoft.com> wrote in message news:1F7136D3-3B22-49B9-AFC7-E6BB1FE47E32@microsoft.com... > Hello, > > A similar problem to my last. I have e...

What is the quickest way to get an xml based dataset to add entries to SQL Server?
Because there is no 'datareader' involved, what is the most efficient way to get an XML based dataset to be added to an SQL server dataset? I would hate to have to create a new SQL connection and iterate through making "executenonquery" for each row in the dataset. That seems horribly in-efficient. I know of no other way to get an xml based dataset to push data to the database though. Any pointers? Thanks for any pointers, Peter Robbins Freelance Programmer C#/PHP "MurdockSE" <murdock@nc.rr.com> wrote in message news:1153922058.675709.165630@h48g2000cwc.go...

Can (or how can) I do this
Hello, My Access application tracks an employee's progress through a process similar to hiring. There are 5 steps in the process. I track 4 of the steps by counting the number of times a value appears in a date field for that step. The count is then displayed and used in a calculation. The 5th step is more complicated. The 5th step needs to determine if the employee has verified that he can access all the applications that he should have access to. My process tracking table has the first 4 dates. The application access info comes from a different table. This process trackin...

how can I restore unsaved changes in excel #2
...

Can Not Connect to Exchange Server after Mailbox Move
I have 2 exchange servers. While logged into the domain, and at the location, I can log into the email system just fine. While remote VPN in, I can not access the server. I can ping the server, I can see all shares, and I can even access the printer and print from the exchange server. But I can not get to it with email. Any Ideas? Oh.. both exchange 5.5, both in the same site. Exchange Admin shows both sites just fine. is there a firewall with rules configured, in between the users vpn connection and the internal network? kmelillo@gmail.com wrote: > Oh.. both exchange 5.5, bot...

Deleting worksheets in a macro
I have a macro that at the end there are 2 work sheets that I delete. When the macro runs, it stops and asks if I really want to delete the worksheets. Is there something I can add so that it will not ask me if I want to delete? Here is what I have. Sheets("Sheet3").Select ActiveWindow.SelectedSheets.Delete Sheets("Sheet2").Select ActiveWindow.SelectedSheets.Delete Thanks Donna Have a look in the below link for details and I hope that you will get some idea. http://www.microsoft.com/office/community/en-us/default.mspx?&query=Ms-Exl-...

Scheduling a macro in outlook 2000
I am trying to schedule a macro to run everyday at a given time, which creates a new email, attaches an excel file and sends it via the internet to another PC, so that there is no input required from a user, i.e. it happens automatically. I can create the email, attach the file and send it, but I cannot schedule it within Outlook. Also when I run the code from Excel, where I can schedule it, only a shortcut is attached to the email. I am using Outlook 2000 (no service release). Has anyone done this before? Can you help? Regards Brian See if the information on the following page ...