- ©«¤l
- 192
- ¥DÃD
- 15
- ºëµØ
- 0
- ¿n¤À
- 194
- ÂI¦W
- 0
- §@·~¨t²Î
- windows
- ³nÅ骩¥»
- office2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¤k
- µù¥U®É¶¡
- 2016-9-22
- ³Ì«áµn¿ý
- 2020-8-28
|
¦^´_ 1# rouber590324 - Sub test()
- Dim sql$, pn$
- Sheet2.Cells.ClearContents
- Sheet2.Range("b:b").NumberFormatLocal = "yyyy/m/d h:mm;@"
- pn = ThisWorkbook.FullName
- sql = "select «~¦W,last(®É¶¡) as ®É¶¡,last(¤º®e) as ¤º®e from [sheet1$] where «~¦W<>null group by «~¦W"
- SqCopy pn, sql, Sheet2.[a2], Sheet2.[a1]
- End Sub
- Sub SqCopy(pt As String, sq As String, Optional Rg As Range, Optional rg1 As Range)
- Dim conn As Object, rst As Object, i%
- Set conn = CreateObject("adodb.connection")
- Set rst = CreateObject("ADODB.recordset")
- Select Case Application.Version * 1
- Case Is <= 11
- conn.Open "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties='excel 8.0;hdr=yes;imex=1';data source=" & pt
- Case Is >= 12
- conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=yes;imex=1';data source=" & pt
- End Select
- Set rst = conn.Execute(sq)
- If Not rg1 Is Nothing Then
- For Each Field In rst.Fields
- rg1.Offset(0, i) = Field.Name
- i = i + 1
- Next
- End If
- If Not Rg Is Nothing Then
- Rg.CopyFromRecordset rst
- End If
- conn.Close
- Set rst = Nothing
- Set conn = Nothing
- End Sub
½Æ»s¥N½X |
|