Toggle Button caption dynamicly changed

steni

New Member
Joined
Aug 3, 2022
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
In my project I have activx toggle button. To this button I have this VBA code:

Private Sub ToggleButton1_Click()
Dim xAddress As String
xAddress = "G"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
ToggleButton1.Caption = "Pokaži Ceno z DDV"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
ToggleButton1.Caption = "Skrij Ceno z DDV"
End If
End Sub

On the same page, I have a drop-down menu with which I can choose the language in which I want the content of the page to be displayed.
I managed to edit the page so, that depending on the selected language, the content is in the corresponding language. Only the text on the toggle button is not translated, because I don't know how to write the code so that the caption would change depending on the selection of the drop-down menu.
How should I fix the above code that caption will be translated too.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
In cell C2 I have data validation dropdown list where I can choose four language: Slovenščina, Deutsch_Österreich, Deutsch_Deutschland and English.
I was try with this VBA code but this is not working:

Private Sub ToggleButton1_Click()
Dim xAddress As String
Set wsA = ActiveSheet
xAddress = "G"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
If wsA.Range("C2").Value = "Slovenščina" Then
ToggleButton1.Caption = "Pokaži Ceno z DDV"
ElseIf wsA.Range("C2").Value = "Deutsch_Österreich" Then
ToggleButton1.Caption = "Brutto anzeigen"
ElseIf wsA.Range("C2").Value = "Deutsch_Deutschland" Then
ToggleButton1.Caption = "Brutto anzeigen"
ElseIf wsA.Range("C2").Value = "English" Then
ToggleButton1.Caption = "Show Gross Price"
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
If wsA.Range("C2").Value = "Slovenščina" Then
ToggleButton1.Caption = "Skrij Ceno z DDV"
ElseIf wsA.Range("C2").Value = "Deutsch_Österreich" Then
ToggleButton1.Caption = "Brutto verstecken"
ElseIf wsA.Range("C2").Value = "Deutsch_Deutschland" Then
ToggleButton1.Caption = "Brutto verstecken"
ElseIf wsA.Range("C2").Value = "English" Then
ToggleButton1.Caption = "Hide Gross price"
End If
End Sub

I have no more idea. Is here someone who is so kind and will help me with my problem.
Than you
 
Upvote 0
I found a working solution myself. Code is:

Private Sub ToggleButton1_Click()
Dim xAddress As String
Dim MyLabel As OLEObject
Set MyLabel = ActiveSheet.OLEObjects("ToggleButton1")
Set wsA = ActiveSheet
xAddress = "G"
If ToggleButton1.Value Then
Application.ActiveSheet.Columns(xAddress).Hidden = True
If wsA.Range("C2").Value = "Slovenščina" Then
ActiveSheet.ToggleButton1.Object.Caption = "Pokaži Ceno z DDV"
ElseIf wsA.Range("C2").Value = "Deutsch_Österreich" Then
ActiveSheet.ToggleButton1.Object.Caption = "Brutto anzeigen"
ElseIf wsA.Range("C2").Value = "Deutsch_Deutschland" Then
ActiveSheet.ToggleButton1.Object.Caption = "Brutto anzeigen"
ElseIf wsA.Range("C2").Value = "English" Then
ActiveSheet.ToggleButton1.Object.Caption = "Show Gross price"
End If
Else
Application.ActiveSheet.Columns(xAddress).Hidden = False
If wsA.Range("C2").Value = "Slovenščina" Then
ActiveSheet.ToggleButton1.Object.Caption = "Skrij Ceno z DDV"
ElseIf wsA.Range("C2").Value = "Deutsch_Österreich" Then
ActiveSheet.ToggleButton1.Object.Caption = "Brutto verstecken"
ElseIf wsA.Range("C2").Value = "Deutsch_Deutschland" Then
ActiveSheet.ToggleButton1.Object.Caption = "Brutto verstecken"
ElseIf wsA.Range("C2").Value = "English" Then
ActiveSheet.ToggleButton1.Object.Caption = "Hide Gross price"
End If
End If
End Sub

I hope it will help someone else.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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