?
Solved

Translating Excel 2003 Macros to Excel 2007

Posted on 2007-10-03
6
Medium Priority
?
7,507 Views
Last Modified: 2012-05-05
I currently have many Macro's written in Excel 2003 that I'm testing in Excel 2007.  Most of the macros add chart objects and begin by deleting all of the current charts using - ActiveSheet.ChartObjects.Delete,
2 questions 1.  What would the translation of the ActiveSheet.ChartObject.Delete command be and
2.  Is there any place / references that help in converting Excel 2003 Macro's to Excel 2007.  
0
Comment
Question by:bbroehm
6 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 20005779
For the most part, as far as I know, the macros should be forward-compatible. The chart engine was completely revised for 2007 though so you may have some issues with those and you will find that the macro recorder does not work with charts in 2007! The only other thing I know of is that Application.FileSearch is discontinued.
I'm not in front of a machine with 2007 on at the moment to test, but are you getting errors with Chartobjects.Delete?
Regards,
Rory
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20005786
HI bbroehm,

Have you tried that code in XL2007? As far as I know, it should still work.

Note that it should be ActiveSheet.ChartObjects.Delete, not ActiveSheet.ChartObject.Delete (note the plural ChartObject).

Regards,

Wayne
0
 
LVL 12

Expert Comment

by:geneus
ID: 20005853
Question 1:

    ActiveSheet.ChartObjects("Chart 2").Delete
-OR-    
    ActiveSheet.ChartObjects(1).Delete

Question 2:
This will show you what the new changes in Excel 2007 are:
http://technet2.microsoft.com/Office/en-us/library/bee594b4-01b1-4d17-90ca-d43735a7382a1033.mspx?mfr=true

Most macros should work but there are object changes that you may need to tweak.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bbroehm
ID: 20007309
A clarification I grabbed a snippet of code with the actual excel error *****'d about 10 lines down .  This code works fne in excel 2003 but not in excel 2007.  The excel error Run time error '1004'  Application defined or object defined eror.  Note the


    ActiveSheet.Cells(7, 1).Select
    'Sheets("System_Plots").Activate
   
    Sheets("System_Plots").Activate
    ActiveSheet.Range("a7").Select
    'ActiveSheet.Cells(7, 1).Select
    ActiveSheet.ChartObjects.Delete  *********
0
 
LVL 12

Expert Comment

by:geneus
ID: 20007461
You have to identify the Chart Object to Delete.
If the ActiveSheet has only 1 chart on it then you can select by index:
ActiveSheet.ChartObjects(1).Delete

If you are deleting multiple charts on a single sheet:

    For a = 1 To ActiveSheet.ChartObjects.Count
        ActiveSheet.ChartObjects(1).Delete
    Next a
0
 
LVL 12

Accepted Solution

by:
geneus earned 150 total points
ID: 20007599
I tested your line:
ActiveSheet.ChartObjects.Delete

In both versions successfully.
The reason you may be getting the error is that the charts were created in a previous version of Excel than 2003 and they are not being recognized as charts.  The error messge you are getting means that the object, in your case, ChartObject, does not exist.  
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question