PDA

View Full Version : [SOLVED] 2007 compatibility



mdmackillop
04-12-2008, 06:53 AM
I came across this problem, which I think may be quite common in opening pre 2007 workbooks from Excel 2007

LastRow = Workbooks("Test.xls").Sheets(1).Range("A" & Rows.Count).End(xlUp).Row

In this case, Rows.Count can take the value of 1048576 from my 2007 workbook, which causes an error as it does not exist in Test.

Fully qualify the Range and the Rows.count by changing to

Sub Test()
With Workbooks("Test.xls").Sheets(1)
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
End With
End Sub

paulked
04-16-2008, 04:47 PM
Many thanks for the info. I'm upgrading today and any anomilies like this will be very helpful to anyone upgrading.

Please continue this sticky!

:work:

CaptRon
05-18-2008, 06:53 PM
Discovered this characteristic about Excel 2007 shortly after our office converted to Office 2007. Thought I'd share it.

The workbooks I had built in Excel 2003, when converted to .xlsm, would not enable macros and wouldn't offer the user the option to do so. I researched the issue online and someone mentioned that the worksheets and workbooks could not be protected or Excel 2007 won't enable macros.

After monkeying around with Excel 2007 for a while, I discovered that Excel 2007 doesn't care if the worksheets are protected, with or without a password, but it WILL NOT enable macros in a workbook that is password protected on open. Period! Won't give you the option to enable either, even if you place the workbook in a "trusted location." The workbook can be protected when opened, just not password protected.

Once the workbook is open, you can apply password protection to the workbook itself and everything works OK because the macros have already been enabled. I am now making sure that workbook protection is removed on close and then reset by the user (click this button to show sheets) after its opened.

FWIW.

Ron

Ken Puls
05-19-2008, 08:37 PM
I just had a FileSearch issue raise it's ugly head for me as well. I know that it doesn't work in 2007 any more, but due to a brain cramp, I tried testing a routine in 2007 that used this method.

Removing it is one thing, but they could at least make it throw an error... As it is right now, the routine just silently ends, without even giving the chance to do anything about it. Not very cool at all. :(

Zack Barresse
05-20-2008, 10:53 AM
Wasn't that stupid? This is what we get from one dumb a$$ progger - ASSUMING! I throw curses at that person..

Ken Puls
05-20-2008, 08:13 PM
I figured it actually came about by committee. In my experience there usually seems to be one of those beyond the most ridiculous decisions...

CaptRon
06-18-2008, 07:17 AM
Xld helped me with an issue that deals with the file format and syntax variances between Excel 2007 and earlier versions.

I created a workbook in Excel 2003 for distribution within our organization. Only about 10% of the agency at this point has migrated to Office 2007. The workbook creates a duplicate of itself and I wanted that duplicate to save in the Excel file format resident on the user's machine.

When the portion of code was added to accommodate the save routine for Excel 2007, it was not recognized by Excel 2003 and was then treated as an undeclared variable.

The solution is found at:

http://vbaexpress.com/forum/showthread.php?t=20220

Ron

Oorang
06-18-2008, 09:07 AM
Does Worksheet.UsedRange.Rows.Count cause any issues?

Bob Phillips
06-19-2008, 02:13 AM
Does Worksheet.UsedRange.Rows.Count cause any issues?

No it won't. It is unlikely that UsedRange would be all rows, and even if it were it would not be a problem as Count is a Long, so it caters for 1M+ rows easily.

However, Worksheet.Cells.Count is a different matter. We are talking 17Billion+ cells here and that overflows Count significantly. Becuase of this, 2007 as an extra property, CountLarge, which returns the answer.

Interestingly, type

?TypeName(Activesheet.Rows.Count)

in the immediate window, and it tells you it is a long. Type

?TypeName(Activesheet.Cells.CountLarge)

and you get a Compile Error.

Oorang
06-19-2008, 08:03 AM
XLD >> That is interesting.

MDMackillop >> Why aren't we just using something like this?

Public Function GetBottomRow(ByRef ofWorksheet As Excel.Worksheet) As Long
Const lngOffset_c As Long = 1
Dim rngUsed As Excel.Range
Set rngUsed = ofWorksheet.UsedRange
GetBottomRow = rngUsed.Rows.Count + rngUsed.Row - lngOffset_c
Set rngUsed = Nothing
End Function

Bob Phillips
06-19-2008, 10:27 AM
Why use



GetBottomRow = rngUsed.Rows.Count + rngUsed.Row - lngOffset_c


isn't rngUsed.Row always 1, so you could just use

Why use



GetBottomRow = rngUsed.Rows.Count


but usedrange has the leftover bug, which spoils it anyway.

Oorang
06-19-2008, 12:02 PM
lol Well mostly because it's not always "1". Create some test data in a worksheet and then insert several empty rows above it. The start of the used range will be the first row with data.

I know, I know... "Who in their right mind would that?"

hehe I can only say I have seen it done:)

(It's usually the same people who think that color is great way to show if an account has been paid or not.)

Bob Phillips
06-19-2008, 01:07 PM
Okay, but you can do it a lot simpler notwithstanding the limitations of UsedRange



Function GetBottomRow(ByVal sh As Worksheet) As Long

With sh
GetBottomRow = .UsedRange(.UsedRange.Count).Row
End With
End Function

Oorang
06-19-2008, 01:28 PM
Looks like a winner to me:)

mdmackillop
09-06-2008, 04:04 PM
... and if Column B data is longer than Column A data?

Bob Phillips
09-07-2008, 02:41 AM
Then it returns the last row of B ...

markmrw
11-26-2008, 05:30 AM
I discovered this after my work PC was upgraded to 2007, while other PC's in the company were still running 2003


.TintAndShade = 0


I used the record macro button. to change some formats on a couple of sheets, and this line of code runs fine with 2007,
but any earlier versions, break and explode causing many of my colleagues much distress and anguish.

thoought this might be handy for all.

Mark

Oorang
11-29-2008, 10:38 AM
Since interest seems to be increasing, here is a comprehensive list of all Adds and Changes to Excel Object Model since 2003:
http://msdn.microsoft.com/en-us/library/bb149069.aspx

As a side note, if you are going to use 2007 methods/properties in a mixed shop it might be beneficial to call them in a wrapper. In this way you will work as expected in either version. Here is a simple example of how to do this:

Sub Test()
ColorRange Selection, Excel.Application.version, 6
End Sub
Sub ColorRange(rng As Excel.Range, version As Double, ParamArray args() As Variant)
With rng.Interior
.colorIndex = 6
.Pattern = xlSolid
If version >= 12# Then
'Because the property name is stored in a string this will still compile.
'And it will only get called if the correct version is in use.
CallByName rng.Interior, "TintAndShade", VbLet, 0
End If
End With
End Sub


Edit:
Just occured to me you could put version inside the wrapper instead of passing it as a parameter. (I know... duh:))

markmrw
12-26-2008, 09:01 AM
Thank you oorang

Very helpful, bookmarked :)
I keep finding many little things, if i find any not listed i will post.
Now that christmas is over, back to the grind stone i suppose. :(

Thanks
Mark

Oorang
01-06-2009, 08:39 AM
Ok, so the last row discussion came up over on MrExcel... And I think this function from Rorya may account for more vagaries than the "usedrange" approach we were discussing.


Public Function LastRowInSheet(wks As Worksheet) As Long
'From Rorya on MrExcel:
'http://www.mrexcel.com/forum/showthread.php?p=1793851&posted=1#post17938521
' Returns the number of the last row with data anywhere in it
LastRowInSheet = 1
On Error Resume Next
With wks.UsedRange
LastRowInSheet = .Cells.Find("*", .Cells(1), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End With
End Function

burtburt
03-01-2009, 08:43 AM
Well I found another issues. 2003 xls sheets with cells that have validation loose there validation when opened in Excel 2007.

This sucks, I had to rebuild them all.

If that's not enough, the whole save as interactive web page is gone in 2007. They want us all to purchase MOSS 2007 + (Excel Servicesfor $25/user/year). Sounds cheap until you start multiplying.

Bob Phillips
03-01-2009, 09:57 AM
Are you sure? I haven't heard this, and so I just tried it. Just a simple list DV I admit, but no problems here.

Are there some particular situation where it happens?

CaptRon
03-01-2009, 10:07 AM
I just opened up one of my workbooks built in Excel 2003 and all the data validation seems to work OK in 2007. The 3 types I checked were list, whole numbers, and dates.

Which type if DV was not working for you?

Ron

mdmackillop
07-04-2009, 02:41 AM
Conditional Formatting
In 2007, cel.FormatConditions(1).Formula1 will return a string like "=2"
previously this was returned as the simple value.

Use Evaluate to get the numeric value

With cel.FormatConditions(1)
myColour = .Interior.ColorIndex
myOp = .Operator
myVal = Evaluate(.Formula1)
End With

burtburt
07-07-2009, 07:52 AM
Ok. I didn't communicate my issue correctly. What I should have said was that to change a validation message in 2007 you need to first delete the old validation (if it exists). In 2003 this worked without deleting it:



Cells(intRow2Write, 7).Validation.InputMessage = strGateCrit



Now I have to delete first then add it from scratch including the validation and the validation message.


With Cells(intRow2Write, 7).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$G$1:$G$4"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Criteria:"
.ErrorTitle = ""
.InputMessage = strGateCrit
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With


Sorry about the confusion.

Bob Phillips
07-07-2009, 08:15 AM
I have just changed the InputMessage in 2007 without deleting the validation. Seems the same to me.

burtburt
07-14-2009, 02:13 PM
Well I guess I'm loosing my credibility fast here. I don't know why I'm having these issues and no one else is. Perhaps it has something to do with creating the validation in an xls in 2003, and trying to update the message on the xls book in 2007. Regardless, I'm going to drop it. "Don't fix it if it ain't broke", my grandpa used to say. Thanks for the ear...

Paul_Hossler
08-21-2009, 01:21 PM
Has anyone experienced formula errors when saving a 2007 WB as a 2003?

A customer has mandated that no one use any office 2007 product due to errors. This includes back-saving Excel 2007 as 2003 due to "formula errors in the 2003 WB."

Google does not locate any articles that seem to address bad formulas being generated

Has anyone heard of this issue?

Paul

Bob Phillips
08-21-2009, 02:59 PM
We have seen disappearing range names, but that was fixed by a hotfix a couple of months back.

ProteanBeing
02-11-2010, 10:30 AM
An issue I found was with the sort method. I recorded a macro in 2007 and it will not function in 2003 because the sort method has changed. My guess is that this will happen with a lot of recorded macros.:bug:

Bob Phillips
02-11-2010, 02:52 PM
But a sort macro recorded in 2003 will work in 2007.Moral of the story, develop on the lowest version.

geekgirlau
02-14-2010, 10:06 PM
Often the problem with recorded macros is new/changed parameters. It's always a good idea to clean up recorded code to remove the stuff you don't need - if you don't need to change a specific parameter and the macro recorder has just inserted the default value, get rid of it!

kestrylr
06-24-2010, 11:44 AM
Thanks for all the tips here! I'm currently still in 2003 at work, but some of the people I support have switched to 2007 and I can already see the headaches piling up on the horizon...

(It's a VERY large company - I have no say in when my computer will be upgraded... :banghead: )

Simon Lloyd
06-26-2010, 08:55 AM
Thanks for all the tips here! I'm currently still in 2003 at work, but some of the people I support have switched to 2007 and I can already see the headaches piling up on the horizon...

(It's a VERY large company - I have no say in when my computer will be upgraded... :banghead: )Trust me, you'll hate the move to 2007, just think of it as if someone swapped your hands over, rearranged the fingers and then turned them back to front and you are trying to thread a needle! :)

I have a true dislike for it, i've moved on to 2010 and it seems a tad better although everything still seems misplaced for me, still hard to get used to.

geekgirlau
06-29-2010, 03:54 PM
It's a HUGE learning curve - it's the first time in years that I've really had to hunt to find things in an Office product upgrade. I have seen some tools rolled out whereby you can go through a faux Office 2003 screen to select an option, and it shows you where the corresponding option lives in 2007.

Getting used to it now (and I do like some of the new features) but my biggest frustration is with the ribbon. Their policy appears to be "I'm going to guess what I think you want to do next, and make the ribbon that you actually want (and hunted for 5 minutes to find) disappear again". I'd love to switch this off (if I could work out how to do it) - contrary to Microsoft's opinion I generally have a slightly better idea of the functions I need to access next then they do!

Simon Lloyd
07-01-2010, 04:33 AM
........ - contrary to Microsoft's opinion I generally have a slightly better idea of the functions I need to access next then they do!Have you told them this? they probably have never heard that before :rotlaugh:

Heaven forbid that they actually listen to their client base and make you a valued part of the development in creating something that we (the collective frustrated office users "We") can actually use to perform our task efficiently!

Charlize
08-30-2010, 05:00 AM
I have a true dislike for it, i've moved on to 2010 and it seems a tad better although everything still seems misplaced for me, still hard to get used to.Know the feeling ... Bosses wanted to go from 2007 (finally everyone was used to it and most things worked back (after some sleepless nights) to 2010 because they have the option for included upgrades.

Sometimes I think, although I know I don't know everything, how hard it must be for my fellow collegues if even I have some difficulties to grasp everything that has been changed.

Charlize

mdmackillop
02-26-2011, 05:34 AM
I found an issue with using Listbox.Selected(i) in 2010 to test for any selected items. In the end I came up with this to be compatible between 2003 & 2010

'Check for Selected; handle 2003 and 2010 versions
If IsNull(ListBox1) And ListBox1.Selected(1) = False Then
MsgBox "No item selected", vbExclamation
Exit Sub
End If

Bob Phillips
02-26-2011, 08:14 AM
Why not test ListIndex?

mdmackillop
02-26-2011, 08:35 AM
Thanks Bob. I new I was missing a trick!

Zack Barresse
03-01-2011, 10:17 PM
I always use ListIndex. What exactly is the issue Malcolm?

mdmackillop
03-02-2011, 01:30 AM
Hi Zack,
I had write some code at home in 2010 and at work in 2003. When I export this userform facility it fails with regard to ListBox.Selected values and when they do not exist. I'm trying to ensure the code will function with both.