Excel VBA ListBox and ComboBox display wrong characters while TextBox provides the correct ones, using the same UserForm.
ListBox And ComboBox provides some Ansi substitute instead of Baltic characters, that is wrong.
I've changed:
charset of form and listBox from 133 into 163 by using ListBox.Font.Charset property
use of font Arial or Times New Roman with Baltic encoding
read through tons of pages on the internet and still no luck..
Thanks for your attention
I used code as follows:
Private Sub UserForm_Initialize()
UserForm2.Font.Charset = 186
ListBox1.List = Array("ĄČęėį", "Žųūįšų", 222) -> does not provide correct text :(
With ListBox1
.AddItem "Vilnius"
.AddItem "Kaunas"
.AddItem "Klaipėda" -> Klaipëda
.AddItem "Šiauliai" -> Ðiauliai
.AddItem Chr(222)
End With
Finally looks like VBA editor has trouble with international characters - if use button caption through Object Properties window - it goes wrong.
But entering labels and button text directly on the form provides correct outcome, hence there is a work around here - use RowSource option, taking data from excel table, which gives right encoding:
ListBox1.RowSource = "=Sheet2!A1:A5"
This solution is convenient to my needs and the question is closed by now.
Thank you for your response.
To populate ListBox and ComboBox with correct international characters I used Object Property window providing RowSource and taking data from Excel table.
In VBA editor it looks like this: ListBox1.RowSource = "=Sheet2!A1:A5"
Such an approach works well with Baltic and Russian languages, I did not try it with other languages.
Related
Has anyone been able to get the time-phased work effort VBA extract macro by Jack Dalhgren, its quite an old macro.
I've been able to create the form and the macro works for the default timephase which is weeks, but if I select another say months I get an error on this line of code. (runtime error 13, type mismatch)
Set pTSV = ActiveProject.ProjectSummaryTask.TimeScaleData(tbstart.Value, tbend.Value, , cboxTSUnits.Value)
http://zo-d.com/blog/archives/programming/analyze-microsoft-project-resource-usage-data-in-excel.html
Thank you
The comboBox in the code uses 2 columns, the text and the internal representation which is a number. The code uses predefined constants for it like pjTimescaleWeeks. The call to TimeScaleData expects this number as parameter.
It is likely that you get the text (a String) as result from the comboBox, (eg "Week"), and this causes the Type mismatch.
You can specify that you want the value of the 2nd column as Value from the combobox. You can do this using the VBE form designer, set property BoundColumn to 2, or you can do this in you code:
Sub fillTSUnitsBox()
...
cboxTSUnits.List = myArray
cboxTSUnits.BoundColumn = 1
cboxTSUnits.Value = 3
End Sub
I am using a ListBox in a UserForm to display the data from a Table in my worksheets. All the data is correctly formatted in the table but in the ListBox, the currency is being displayed with an "error symbol" which should simply be a space (as per the french standard for currency formatting) and looks like the following :
I won't add the code for the UserForm since I am only having issues when inserting the data into the ListBox. However, below is the code responsible for populating said ListBox where msOperationTable is of type ListObject :
TableEntries.ColumnCount = 6
TableEntries.ColumnHeads = True
TableEntries.ColumnWidths = "100; 140; 150; 85; 100; 70"
TableEntries.RowSource = msOperationTable.Parent.Name & "!" & msOperationTable.DataBodyRange.Address
I haven't been able to find any explanation as to why this happens and I am starting to wonder if there is anything that can be done to fix this.
I am fairly new to VBA so any help would be greatly appreciated.
I have a UserForm that contains 3 labels and 3 text boxes. 2 of the text boxes (including the first one that is activated upon the form's activation) are empty. The third has 3 characters pre-filled into it. When the userform starts, I would like to fill in the first text box as normal then when I tab into the second text box, I would like the cursor to automatically go to the end of that 3 letters instead of highlighting the entire text box. I have looked around but cannot seem to find anything that can do this easily. Could you please let me know where exactly (which sub) to enter this code into as well?
My UserForm is called 'GetBIInfo2' and my text box is called 'NBIDText'
Thanks!
Select the textbox.
Go to property (F4).
Scroll till you find EnterFieldBehavior property.
Change it to 1 - FmEnterFieldBehaviorRecallSelection.
The direct approach is via the textbox'es .SelStart property; possibly you might call it via a sub procedure like this:
Sub fillAnyTextBox(myTextBox As MSForms.TextBox, ByVal firstCharacters As String)
With myTextBox
.Value = firstCharacters
.SetFocus
.SelStart = Len(firstCharacters)
.SelLength = Len(.Text) - Len(firstCharacters)
End With
End Sub
A simple alternative would be to make another text box to hold the first three characters and have the user enter the following characters into a separate textbox. Then you can write code that will take the contents of both and append them into a single string like this:
Dim finalString As String
finalString = TextBox1.Value & TextBox2.Value
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I've created a Userform in Excel VBA, on which there is an unbound Listbox that has its MultiSelect property set to Extended. When that listbox receives focus by any means other than clicking a list item, all items in that list appear with the dotted focus rectangle around them.
Here is some code that shows the phenomenon beside another listbox with MultiSelect set to Single for comparison. Create a Userform, put two Listboxes on it, and add the code to the form. When you launch the form, tab between listboxes to see what I've described.
Private Sub UserForm_Activate()
ListBox1.MultiSelect = fmMultiSelectSingle
ListBox2.MultiSelect = fmMultiSelectExtended
Dim i As Integer
For i = 1 To 15
ListBox1.AddItem String(i, Chr(i + 64))
ListBox2.AddItem String(i, Chr(i + 64))
Next
End Sub
Is there a way to remove the focus rectangles or prevent their appearing?
Thanks,
I have experimented with your code in Excel 2010 and confirm your observation. If I create two list boxes, enter the code provided, start the form and press tab to focus on ListBox2, the dotted lines appear around all rows.
If I create the two list boxes as before, manually set ListBox2/Properties/Multiselect to 2 - fmMultiSelectExtended, run and tab to ListBox2 the nasty lines disapperar.
For me this is rather stable, the form now survives multiple window activation changes, jumpng back/forth etc.
don't ask me why ...