Question on running older macros in Excel 2007

H

Harlan Grove

Jeremy said:
Will macros created in Excel '97 continue to work in Excel 2007?

For the most part, yes, but there could be some things that don't.
Anything involving iterating through cells in the new, larger
worksheet grid would need to be abstracted, e.g., iterating from 1 to
ActiveSheet.Rows.Count rather than 1 to 1048576 (2^20). Conditional
formatting, sorting, table manipulation, etc method calls, so
involving Excel 2007-specific features, would need to be wrapped
inside conditional compilation constructs so the code would only be
live in Excel 2007 and ignored in previous versions.

But macros that won't run under Excel 2003 won't cause your computer
to blow up. They'll only throw runtime errors. In other words, it's
safe enough to test them under Excel 2003.

In future this sort of question would be better asked in the
microsoft.public.excel.programming newsgroup rather than this one.
Here's a url.

http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.excel.programming
 
H

Harlan Grove

Jeremy said:
Will macros created in Excel '97 continue to work in Excel 2007?

Sorry. My last reply mistakenly assumed the other direction.

There could be more problems trying to run macros developed in older
versions in Excel 2007. Fewer problems with object model method calls,
but more problems due to the new bigger worksheet grid. The single
biggest potential problem is the Count property of the Range class. Up
to Excel 2003, entire worksheets had at most 16,777,216 cells (65536
rows by 256 columns). Now they could have 19,165,872,128 cells
(1,048,576 rows by 18278 columns). The Count property is still type
Long (able to handle numbers up to 2,147,483,647) in Excel 2007, so
something like

Dim n As Long

n = ActiveSheet.Cells.Count

will throw an overflow error in Excel 2007, and changing n's type to
Double won't fix that because the overflow occurs in *.Count. To be
safe, you'd need to change the type to Double for EVERY variable that
COULD be assigned a range object's .Count property, and you'd need to
change every range.Count call to range.CountLarge, which is type
Double.
 
Top