|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
需要修改的地方挺多:- Private Sub UserForm_Initialize()
-
- With 选择 '内页数量 复合框赋值
- .AddItem "打印记录"
- .AddItem "操作记录"
- .AddItem "备用表"
- .ListIndex = -1
- End With
-
- End Sub
- Sub 设置初值()
- Dim i&, j&, arr, a(), k, m%, n%
- With 打印记录
- arr = .Range("A2").CurrentRegion
- ReDim a(UBound(arr, 2) - 1)
- For i = 0 To UBound(a)
- a(i) = .Columns(i + 1).ColumnWidth * 7.5 'ListView1各列列宽
- Next
- End With
- Set cnn = New ADODB.Connection
- cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
- SQL = "select * from [" & ActiveSheet.Name & "$]"
- Set rs = New ADODB.Recordset
- rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
- On Error Resume Next
- With ListView1
- ' 设置ListView1的标题,显示类型,整行选择和网格线属性
- .ColumnHeaders.Clear
- .View = lvwReport ' listivew的显示格式为报表格式
- .FullRowSelect = True ' 允许整行选中
- .Gridlines = True ' 显示网格线
- ' 为ListView1设置标题
- For i = 0 To rs.Fields.Count - 1
- Set k = Controls.Add("Forms.TextBox.1", "TextBox" & i + 1, False) '模糊查询定义False为不显示TexBox ,True为显示
- If i > 0 Then
- .ColumnHeaders.Add , , rs.Fields(i).Name, a(i), lvwColumnCenter '从第2列起居中
- Else
- .ColumnHeaders.Add , , rs.Fields(i).Name, a(i)
- End If
- Next i
- End With
- Call 显示数据(SQL) '为ListView1设置各行数据
- 模糊查询.SetFocus
- End Sub
- Private Sub 选择_Change() '选择窗口选择数据录入的工作表 2
- Select Case 选择.Value
- Case "打印记录"
- 打印记录.Activate
- Case "操作记录"
- Sheet2.Activate
- Case "备用表"
- Sheet3.Activate
- End Select
- 模糊查询.Text = ""
- Call 设置初值
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|