|
发表于 2014-2-27 19:08
|
显示全部楼层
本楼为最佳答案
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Address = "$D$1" Then
- Dim cnn As Object, SQL$
- Dim str$
- Set cnn = CreateObject("adodb.connection")
- Set Rst = CreateObject("ADODB.Recordset")
-
- Select Case Application.Version * 1 '设置连接字符串,根据版本创建连接
- Case Is <= 11
- cnn.Open = "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\data.mdb;Jet OLEDB:Database Password=695360052"
- Case Is >= 12
- cnn.Open = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\data.mdb;Jet OLEDB:Database Password=695360052"
- End Select
- SQL = "select distinct 单位名称 from 信息汇总"
- Rst.Open SQL, cnn, 1, 3
- Do While Not Rst.EOF
- str = str & "," & Rst.fields(0)
- Rst.movenext
- Loop
- With Target.Validation
- .Delete
- .Add Type:=xlValidateList, Formula1:=Mid(str, 2)
- End With
- cnn.Close
- Set cnn = Nothing
- End If
- End Sub
复制代码 你这个单位只有一个啊。。。。 |
评分
-
查看全部评分
|