How to avoid localization of Excel object names and macro splitting?

I have this line of code in my macro:

ActiveSheet.ChartObjects("Chart 6").Activate

When I open the file and run the macro in a non-English version of Excel, this code breaks. For example, in the Japanese system, I tested it, I would need to change the previous line to:

ActiveSheet.ChartObjects("グラフ 6").Activate

(グ ラ フ means "Chart in Japanese")

This seems ridiculous, as these are the names of objects that should not be publicly read, but are used to identify objects. Is there a way to work regardless of the Excel language?

+3
source share
2 answers

, , , ... , .

, :

ActiveSheet.ChartObjects("Chart 6").Activate

:

ActiveSheet.ChartObjects(6).Activate

, " 6" 6, . , , , " 6" one (1).

, , , .

?

: Laurent

, , , ""?

! !

, , . , " 6" "グ ラ フ 6". , , , "6". , , , . , , " 6", , , " " - , .

, :

ActiveSheet.ChartObjects("Chart 6").Activate

:

ActiveSheet.ChartObjects("Motorboat").Activate

, . , , , , , , . , , , , .

, !

Mike

+1

, , , .

, , - For Each . :

Sub DoSomethingWillAllChartObjects()

Dim cs As ChartObject
Dim ws As Worksheet
Dim wb As Workbook

Set wb = ThisWorkbook

For Each ws In wb.Worksheets
    For Each cs In ws.ChartObjects
        Debug.Print cs.Name, cs.Index

    Next cs
Next ws

End Sub

- . , - .

, , For Each , If ... Then, , ChartObject .

0

Source: https://habr.com/ru/post/1729342/


All Articles