Excel VBA macro Diagram 1 as chart 1

Peter90

New Member
Joined
Jul 30, 2014
Messages
17
Hy everybody!
I have got a problem because of the Excel language pack perhaps... I've got a Diagram 1 (hungarian name of the chart) and the Excel macro refers to Chart 1 in the english version of the Excel. In the Hungarian version the macro in the macro record function enter the Diagram 1 name. How could I make equal the two name in the macro?

Diagram as Chart 1 (back and forth)

So this is the problem:




Dim z As String

z = "Chart 1" = "Diagram 1"

ActiveSheet.Shapes(z).ScaleWidth 2.3, msoFalse, _
msoScaleFromTopLeft
ActiveSheet.Shapes(z).ScaleHeight 2.9, msoFalse, _
msoScaleFromTopLeft

But it's failing all over the time and I don't know why.

Please help me,
Thank you in advance!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi Peter,

It is failing because the code will compare the values "Chart 1" and "Diagram 1" and always assign "False" to the variable z

You can confirm that with this simple test...

Code:
Sub Test()
 Dim z As String
   
 z = "Chart 1" = "Diagram 1"
 MsgBox "Z= " & z
   
End Sub


If you need to be able to vary your code based on the Language Pack that is being used by the Application, you could try this....
Code:
Sub ShapeNameBasedOnLanguageID()
 Dim sShapeName As String

 Select Case Application.LanguageSettings.LanguageID(msoLanguageIDUI)
   '--Hungarian
   Case msoLanguageIDHungarian: sShapeName = "Diagram 1"
   '--default is English
   Case Else: sShapeName = "Chart 1"
 End Select
 
 With ActiveSheet.Shapes(sShapeName)
   .ScaleWidth 2.3, msoFalse, msoScaleFromTopLeft
   .ScaleHeight 2.9, msoFalse, msoScaleFromTopLeft
 End With
      
End Sub
 
Upvote 0
Just another possibility if the worksheet contains only one Chart:

Code:
z = ActiveSheet.ChartObjects(1).Name
 
Upvote 0
Wow! :)
Thank you very much! I used the last solution, because I have only one chart on the sheet, but I note all of the solutions, these may come in handy. :)
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,917
Members
449,055
Latest member
KB13

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top