VBA Sub switchLanguage()

DDelainy

New Member
Joined
Dec 22, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hello there,
I'm creating a bi-lingual template that need to have functionality to switch language En/Fr in certain cells.
1. I created a separate sheet ("EN-FR") with English wording in column A and French working in column B
2. On the main sheet I used OFFSET function to indicate English/French wording, for example =OFFSET('EN-FR'!$A$2,0,'EN-FR'!$B$2)
3. I added an ActiveX button that will be called Français or English depending on which language you're switching to.
4. Can you please help me figuring out the code? I assume I need to call the button btnLang and call switchLanguage sub. The button caption needs to switch from Français to English when we translate document into French and vice versa. The sheet is obviously protected, with "Password1"

Private Sub btnLang_Click()
Call switchLanguage

Sub switchLanguage()


Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Maybe something like this
VBA Code:
Private Sub btnLang_Click()
  switchLanguage (btnLang.Caption)
End Sub

Sub switchLanguage(strCaption As String)

Select Case strCaption
     Case "French"
          'do stuff for French?
          btnLang.Caption = "English"
     Case "English"
          'do stuff for English?
          btnLang.Caption = "French"
End Select

End Sub
I might set a range object based on that and do something to it, or maybe alter the sheet formula but I have no idea what that would involve.
 
Upvote 0
Thanks for that @Micron I tried playing with it but couldn't make it work. Would you have any other suggestions?
 
Upvote 0
Yes - post what you tried. "Doesn't work" doesn't help anyone to help you. What was your result?
Please post code within code tags (vba button on posting toolbar) to maintain indentation and readability.
 
Upvote 0
Hi @Micron I went into another direction. I used IF function in each cell with reference to cell "B1" that toggles between value "0" and "1".

VBA Code:
Private Sub btnLang_Click()
ActiveSheet.Unprotect "Password1"
    With Range("B1")
    .Value = IIf(.Value = 1, 0, 1)
  
  'toggle button captions
  btnLang.Caption = IIf(Range("B1").Value = 0, "Francais", "English")
    End With
ActiveSheet.Protect "Password1"
End Sub

I'm testing it now (as I have a few drop-downs and another value-dependent VBAs, fingers crossed it works well for me. Thanks!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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