Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

language problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rj - 13 Nov 2007 14:03 GMT
Hi All,

I have a few VBA forms in a word doc.
What i want to do is have a language drop down on the first form, and
if for example, the user selects Spanish, all the labels on that form,
as well as other forms labels should change to Spanish.
My current approach of putting in a bunch of if..then statements is
causing it to hang.

Is there a more efficient approach?

Thanks in advance!
Astrid - 15 Nov 2007 02:16 GMT
Hi RJ,

> What i want to do is have a language drop down on the first form, and
> if for example, the user selects Spanish, all the labels on that form,
> as well as other forms labels should change to Spanish.

I guess we're talking about a userform and not a protected document?
If so, there are different approaches to use:

- Create an ini-file with the different languages as sections and the
labelnames as keys. Use the translation as value.
- If the translations are not really long strings, put them in the tag of
the control on the userform and separate them by a special sign that's not
used in the translation, for example a tilde (~)

Read the translation on the after_update of the combobox with languages or
the change event of a multipage.

For the code I wrote for this example I used an userform with a combox and
two labels. In the tag property of the labels I entered first a text for
Spanish followed by a ~ (the separaton sign) and then the text for English.
Label1 for example has the tag Spanish 1~English 1

Private Sub ComboBox1_AfterUpdate()
Dim oControl As MSForms.Control

 If ComboBox1.ListIndex <> -1 Then
   For Each oControl In Me.Controls
     If TypeOf oControl Is MSForms.Label Then
       If Len(oControl.Tag) > 0 Then
         oControl.Caption = GetSubString(oControl.Tag,  _
                                     ComboBox1.ListIndex + 1, "~")
       End If
     End If
   Next
 End If
 
 Set oControl = Nothing
 
End Sub

Private Sub UserForm_Initialize()
 With ComboBox1
   .Clear
   .AddItem "Spanish"
   .AddItem "English"
 End With
End Sub

Function GetSubString(ByVal sStringIn As String, ByVal iPart As Integer, _
            ByVal sSeparationSign As String) As String
Dim iPos As Integer
Dim iLaatstePos As Integer
Dim iLoop As Integer
Dim iPos1 As Integer

 iPos = 0
 iLaatstePos = 0
 iLoop = iPart

 Do While iLoop > 0
   iLaatstePos = iPos
   iPos1 = InStr(iPos + 1, sStringIn, sSeparationSign)
   If iPos1 > 0 Then
     iPos = iPos1
     iLoop = iLoop - 1
   Else
     iPos = Len(sStringIn) + 1
     Exit Do
   End If
 Loop
 If (iPos1 = 0) And (iLoop <> iPart) And (iLoop > 1) Then
   GetSubString = ""
 Else
   GetSubString = Mid(sStringIn, iLaatstePos + 1, iPos - iLaatstePos - 1)
 End If
 
End Function

Hope this helps,
kind regards,
Astrid
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.