|
本帖最后由 张雄友 于 2014-5-18 03:23 编辑
如何按拼音首字母降序排序??见效果。- Sub SQL()
- Dim Conn As Object, Rst As Object
- Dim strConn As String, strSQL As String
- Dim i As Integer, PathStr As String
- Set Conn = CreateObject("ADODB.Connection")
- Set Rst = CreateObject("ADODB.Recordset")
- PathStr = ThisWorkbook.FullName
- Select Case Application.Version * 1
- Case Is <= 11
- strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & PathStr
- Case Is >= 12
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
-
- Conn.Open strConn
- strSQL = "SELECT * FROM [学生$] ORDER BY 姓名 " '如何按拼音首字母降序排序??见效果。
- Set Rst = Conn.Execute(strSQL)
- With Sheets("提取")
- .Cells.Clear
- For i = 0 To Rst.Fields.Count - 1
- .Cells(1, i + 1) = Rst.Fields(i).Name
- Next i
- .Range("A2").CopyFromRecordset Rst
- .Cells.EntireColumn.AutoFit
- .Cells.EntireColumn.AutoFit
- End With
- Rst.Close
- Conn.Close
- Set Conn = Nothing
- Set Rst = Nothing
- End Sub
复制代码
- Sub SQL()
- Dim Conn As Object, Rst As Object
- Dim strConn As String, strSQL As String
- Dim i As Integer, PathStr As String
- Set Conn = CreateObject("ADODB.Connection")
- Set Rst = CreateObject("ADODB.Recordset")
- PathStr = ThisWorkbook.FullName
- Select Case Application.Version * 1
- Case Is <= 11
- strConn = "Provider=Microsoft.Jet.Oledb.4.0;Extended Properties=excel 8.0;Data source=" & PathStr
- Case Is >= 12
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=""Excel 12.0;HDR=YES"";"""
- End Select
- Conn.CursorLocation = 3
- Conn.Open strConn
- strSQL = "SELECT * FROM [学生$]" '如何按拼音首字母降序排序??见效果。
- Set Rst = Conn.Execute(strSQL)
- Rst.Sort = "姓名 desc"
- With Sheets("提取")
- .Cells.Clear
- For i = 0 To Rst.Fields.Count - 1
- .Cells(1, i + 1) = Rst.Fields(i).Name
- Next i
- .Range("A2").CopyFromRecordset Rst
- .Cells.EntireColumn.AutoFit
- .Cells.EntireColumn.AutoFit
- End With
- Rst.Close
- Conn.Close
- Set Conn = Nothing
- Set Rst = Nothing
- End Sub
复制代码
|
|