开发者

Excel VBA behaves different in different languages

Win-XP, Excel 2003

I have a range defined by a name, which is filled by a query. The same named range forms the source of a cell validation (in-cell dropdown list). In my VBA this range is accessed via a range object named LOVL2.

Each time the range is re-filled by the query, its name is redefined to include all rows I obtained through the query. This is done with statement

LOVL2.CurrentRegion.Name = LOVL2.Name.Name

the statement works fine as long as MS Office language is set to English, but the statement fails when MS office language is set to French .... I get Error 1004 "Invalid Name"

Anyone got an idea what is causing this only when MS Office language is set to FRENCH but not while in ENGLISH? (maybe problem with ";" vs "," within the object ??)

Thanks in advance MikeD


edit 12-Aug-2010

the REAL root cause is clear now:

the range's name is "L2PoP" which in the ENGLISH version is recognized as a valid name for a range - in that you can go to any empty sheet, select a range and name it "L2PoP".

Set your user language to FRENCH, go to any empty sheet, 开发者_运维技巧select a range and name it "L2PoP", and you get an error saying "Nom non valide".

so the real curing action is to give a different name to the range which is accepted by both French and English

I can only speculate about what is causing this, it may have to do with the fact that the first 2 characters look like a cell address, on the other hand "A1PoP " is a valid name, whereas "L2Foo" and "L1Foo" are invalid.

strange, but .....


which is filled by a query

By a query table?
A query table's result range already has a name which is the name (a bit sanitised) of the query table itself (set in the properties dialog). Which means you don't need to redefine anything.

And if you do, then try this code:

Sub asfgsdfg()

  Dim n As Name
  Set n = ThisWorkbook.Names("LOVL2")

  'Or in case of a local name,
  'Set n = ThisWorkbook.Worksheets("The worksheet").Names("LOVL2")

  ChangeNamedRangeAddress n, n.RefersToRange.CurrentRegion

End Sub

Public Sub ChangeNamedRangeAddress(ByVal n As Name, ByVal NewRange As Range)
  n.RefersTo = "='" & Replace(n.RefersToRange.Worksheet.Name, "'", "''") & "'!" & NewRange.Address(True, True, xlA1)
End Sub

EDIT

In regard to the follow-up... Most strange and amusing.

Try using a leading underscore or something?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜