Excel language

buddyB

Member
Joined
Nov 13, 2003
Messages
10
Location
Eindhoven, NL
Hello,

Is it possible before i open an excelsheet to check which language of Excel is installed?
Im opening an excelsheet and read data, if i dont set the language correct the program returns an error.

I use:
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
-----------------------
Open Excel
PROGRAM
Close Excel
------------------------
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI



to set the regional settings to English because there is an English version of Excel installed. I want to protect te program, if the installed version of Excel is not English, i want to set the regional settings to that language. How can i do this and is it even possible

Thanks

BuddyB
 
I am a US-Only developer, so I really do not know how to deal with these kinds of issues... but I think you are looking for the Application.LanguageSettings Object. The help files give the following:
Returns information about the language settings in a Microsoft Office application.

Using the LanguageSettings Object

Use Application.LanguageSettings.LanguageID(MsoAppLanguageID ), where MsoAppLanguageID is a constant used to return locale identifier (LCID) information to the specified application.

MsoAppLanguageID can be one of these MsoAppLanguageID constants.
msoLanguageIDExeMode
msoLanguageIDHelp
msoLanguageIDInstall
msoLanguageIDUI
msoLanguageIDUIPrevious

The following example returns the install language, user interface language, and Help language LCIDs in a message box.

MsgBox "The following locale IDs are registered " & _
"for this application: Install Language - " & _
Application.LanguageSettings.LanguageID(msoLanguageIDInstall) & _
" User Interface Language - " & _
Application.LanguageSettings.LanguageID(msoLanguageIDUI) & _
" Help Language - " & _
Application.LanguageSettings.LanguageID(msoLanguageIDHelp)

Use Application.LanguageSettings.LanguagePreferredForEditing to determine which LCIDs are registered as preferred editing languages for the application, as in the following example.

If Application.LanguageSettings. _
LanguagePreferredForEditing(msoLanguageIDEnglishUS) Then
MsgBox "U.S. English is one of the chosen editing languagess."
End If
I would try to help you out more, but to be honest, I dont even know what a "LCID" is, but Im hoping/expecting that you do?
 
Thank you very much Mike R, its the solution to my problem.
The program is now protected against other language installations of Excel.
I was already testing with the LanguageSettings but i didnt get it to work.
Now it works.
Thanks again.

BuddyB
 
Hi Buddy, glad it helped. :)

Would you mind explaining a bit what this does or how you use it? How do you "protect" the language, for example?

Just curious, not looking for anything elaborate, but just the basics, if you wouldnt mind explaning...
 
Protect excel language

Dear Mike R,

If the language settings of the PC is different then the language of the installed language of Excel the software i wrote returns an error. So i have to make sure that while i read the excel file the languages are the same.


code:

Public Sub ExelFileLezen()
xlRows = 0
Dim ExcelTaal As Integer
Dim RegionalString As String
Open het Exel bestand
Dim xlsApp As New Excel.Application
xlsApp.UserControl = True
ExcelTaal = xlsApp.LanguageSettings.LanguageID(Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDInstall) Lees de geinstalleerde Excel Taal in
Select Case ExcelTaal Selecteer een taal
Case 1033 : RegionalString = "en-US" Zet de Regional settings op Engels-United States
Case 1043 : RegionalString = "nl-NL" Zet de Regiomal settings op Nederlands-Nederlands
Case Else : RegionalString = "en-US" Zet de Regional settings op Engels-United States
End Select
Zorg voor regional Settings
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture Onthou de Regional settings
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo(RegionalString) Zet de Regional settings op Engels-United States
If File.Exists(FilePath & "KnopBestand.xls") Then Kijkt of de KnopBestand-file bestaat
Open het Exel-sheet
xlsBook = xlsApp.Workbooks.Open(FilePath & "KnopBestand.xls")
Dim xlsSheet As Excel.Worksheet = xlsBook.Worksheets("Knopbestand")
For y = 1 To xlsSheet.UsedRange.Rows.Count Tel het aantal Rijen uit Exel-sheet
xlRows = xlRows + 1
Next y MsgBox("Rows" & xlRows)
For x = 1 To xlsSheet.UsedRange.Columns.Count Tel het aantal kolomen uit Exel-sheet
xlColumns = xlColumns + 1
Next x MsgBox("Col" & xlColumns)
ReDim BMSArray(xlRows, xlColumns) Stel de grenzen van het array in!
Vul het Array met waardes uit de ExelFile
xlsRng = xlsSheet.Range(xlsSheet.UsedRange.Columns.Address) Range v/h Excelsheet
BMSArray = DirectCast(xlsRng.Value, Object(,)) Vul het BMSArray
Sluiten van het Exel bestand
xlsBook.Sheets("knopbestand").Close()
xlsRng = Nothing
xlsSheet = Nothing
xlsApp.Workbooks.Close()
xlsBook = Nothing
xlsApp.Quit()
xlsApp = Nothing
GC.Collect()
Else : MsgBox("Kan de KnopBestand file niet vinden.")
End If
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI Zet de Regional Setting terug naar "oude" waarde
y = 2 1ste regel is vast, hierin staan de benamingen, niet inlezen
AantalKnop = 0
For y = 2 To xlRows Bepalen van het aantal knoppen(tags)
TagStatus = Val(BMSArray(y, 1))
ResultStatus = String.Compare(TagStatus, TagVerandering)
If ResultStatus <> 0 Then Kijk of we met een nieuwe knop te maken hebben
AantalKnop = AantalKnop + 1
End If
TagVerandering = TagStatus Maak TagVerandering gelijk aan TagStatus
Next y
y = 0
End Sub

i hope this is enough for you, otherwise reply, and i try to explane it to you

BuddyB
 
Back
Top