i am using apache POI to add rows to excel file.
I need to create combobox (list box) in my excel file.
do you know if it's possible ? how can I do it ?
Thanks
Printable View
i am using apache POI to add rows to excel file.
I need to create combobox (list box) in my excel file.
do you know if it's possible ? how can I do it ?
Thanks
try this:
This is untestedCode:Dim sName(20) As String
Dim sNum(20) As String
Private Sub Form_Load()
Open "textfile.txt" For Input As #1
Index = 0
Do Until EOF(1)
If Index > 19 Then
MsgBox "Sorry, Only 20 Numbers/Names at one time please.", vbCritical, "Users"
Exit Do
End If
Index = Index + 1
Input #1, sNum(Index), sName(Index)
Combo1.additem = sNum(Index)
Loop
Close #1
End Sub
Private Sub Combo1_Click
call Combo1_Change
End Sub
Private Sub Combo1_Change
Text1.text=sName(combo1.value)
End Sub
please let me know if it works
BTW. This will let you have up to 20 numbers and names. any more than that and you'll have to increase the no. 20's and the no. 19 by the same amount....
I have a problem with this tho
Private Sub cboCentreNumber_Change()
txtCentreDescription.Text = sName(cboCentreNumber.Text)
End Sub
i get a subscript out of range error
Any ideas
Thanks again
try this new code:
ps: you might want to lock text1Code:Dim sName(20) As String
Dim sNum(20) As String
Private Sub Form_Load()
Open "textfile.txt" For Input As #1
Index = 0
Do Until EOF(1)
If Index > 19 Then
MsgBox "Sorry, Only 20 Numbers/Names at one time please.", vbCritical, "Users"
Exit Do
End If
Index = Index + 1
Input #1, sNum(Index), sName(Index)
Combo1.AddItem sNum(Index)
Loop
Close #1
End Sub
Private Sub Combo1_Click()
Call Combo1_Change
End Sub
Private Sub Combo1_Change()
Text1.Text = sName(Combo1.Text)
End Sub