|
加上超链接功能,为了按照每个工作簿添加一个超链接,就不再使用联合查询了:
- Sub ado查询()
- Dim cnn As Object, rs As Object, SQL$, f$, p$, r&, sh As Worksheet, objWMI As Object
- Const HKEY_LOCAL_MACHINE = &H80000002
- Set objWMI = GetObject("winmgmts:\\.\root\default:StdRegProv")
- objWMI.SetDWORDValue HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines\Excel", "TypeGuessRows", 200
- Application.ScreenUpdating = False
- [a1].CurrentRegion.Offset(1).ClearContents
- r = 2
- Set sh = ActiveSheet
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls")
- While f <> ""
- If f <> ThisWorkbook.Name Then
- Set cnn = CreateObject("adodb.connection")
- Set rs = CreateObject("adodb.recordset")
- cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='excel 8.0;imex=1';Data Source=" & p & f
- SQL = "select * from [工作表目录$]"
- rs.Open SQL, cnn, 1, 3
- Cells(r, 1).CopyFromRecordset rs
- sh.Hyperlinks.Add Anchor:=Cells(r, 1).Resize(rs.RecordCount), Address:=p & f 'A列添加超链接
- r = r + rs.RecordCount
- End If
- f = Dir()
- Wend
- With ActiveSheet.UsedRange
- .Value = .Value
- End With
- cnn.Close
- Set cnn = Nothing
- Set objWMI = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|