[求助]combo组合框问题
请问各位大侠,如何实现以下功能:现有combo1和combo2两个组合框,combo1中有值“一”和“二”,当选中“一”时,combo2下拉框中显示a.xls表sheet1中第1列值;当选中“二”时combo2下拉框显示a.xls表sheet1中第2列值。
请问下面代码中的红色部分应该如何修改?如果用循环语句或case语句应该如何写?谢谢!
Option Explicit
Private Sub Form_Load()
Dim xlsapp As Excel.Application
Dim xlsworkbook As Excel.Workbook
Dim xlssheet As Excel.Worksheet
Combo1.AddItem "一"
Combo1.AddItem "二"
Set xlsapp = CreateObject("excel.application")
Set xlsworkbook = xlsapp.Workbooks.Open(App.Path & "\a.xls")
xlsapp.Visible = False
Set xlssheet = xlsworkbook.Worksheets.Item(1)
Dim h As Integer, l As Integer
h = xlssheet.UsedRange.Rows.Count
l = xlssheet.UsedRange.Columns.Count
Dim i As Integer, j As Integer
If Combo1.Text = "一" Then
Combo2.Clear
For i = 1 To h
Combo2.AddItem xlssheet.Cells(i, 1)
Next i
Combo2.ListIndex = 0
ElseIf Combo1.Text = "二" Then
Combo2.Clear
For j = 1 To h
Combo2.AddItem xlssheet.Cells(j, 2)
Next j
Combo2.ListIndex = 0
End If
xlsapp.Quit
Set xlssheet = Nothing
Set xlsworkbook = Nothing
Set xlsapp = Nothing
End Sub
a.rar
(1.94 KB)
[ 本帖最后由 桃源书生 于 2009-11-19 22:41 编辑 ]