|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub ListView1_DblClick()
Me.L2.Caption = ListView1.ListItems(ListView1.SelectedItem.Index).Text
Me.L3.Caption = Me.ListView1.SelectedItem.SubItems(1) '第二列
If InStr(L3.Caption, "伍山") Then s = "39伍山村"
If InStr(L3.Caption, "明德") Then s = "01明德社区"
p = ThisWorkbook.Path & "\原文\" & s & "\" & Me.L2.Caption
Dim folderPath As String
folderPath = p ' 双击打开选中的文件夹
Shell "explorer " & folderPath, vbNormalFocus
End Sub
Private Sub TextBox1_Change()
Call chaxun
End Sub
Private Sub UserForm_Initialize() '加载
Call chaxun
End Sub
Sub chaxun()
Dim Sql$, line&, i&
Application.ScreenUpdating = False
Set cnn = CreateObject("adodb.connection")
Set rst = CreateObject("ADODB.RecordSet")
s = TextBox1.Text
With cnn
.Open "Provider=Microsoft.Ace.oledb.12.0;extended properties='excel 12.0;HDR=yes';data source=" & ThisWorkbook.Path & "\档案目录.xls"
Sql = "select 档号,题名 from [Sheet1$] where 题名&档号 like '%" & s & "%'"
End With
rst.Open Sql, cnn, 1, 3
With ListView1
.ColumnHeaders.Clear '先清空listview的表头
.ListItems.Clear '清空记录
.View = lvwReport '以报表的形式
.Gridlines = True '显示网格线
For i = 0 To rst.Fields.Count - 1
.ColumnHeaders.Add , , rst.Fields(i).Name, 100 * (i + 2), lvwColumnLeft
Next i
.ListItems.Clear
For i = 1 To rst.RecordCount
.ListItems.Add , , rst.Fields(0).Value
For j = 1 To rst.Fields.Count - 1
.ListItems(i).SubItems(j) = rst.Fields(j).Value
Next j
rst.MoveNext
Next i
End With
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
|
|