让您瞬间完成很多重复的工作
二、双击Sheet1,输入VBA代码
具体代码如下,仅供参考:
Option ExplicitDim oCnn As Object, oRst As Object, sFile As StringSub openSQL() Set oCnn = CreateObject("adodb.connection") Set oRst = CreateObject("adodb.recordset") oCnn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullNameEnd SubSub closeSQL() If oRst.State = 1 Then oRst.Close If oCnn.State = 1 Then oCnn.Close Set oRst = Nothing Set oCnn = NothingEnd SubSub fenbiao() Dim sql As String, sql2 As String Dim Arr_CateNumS, Arr_CateNumI Dim Arr_Cate openSQL sql = "select 单位名称 as wjm from [Sheet1$a3:l295] group by 单位名称" oRst.Open sql, oCnn, 1, 1 Arr_Cate = oRst.getrows() Arr_CateNumS = UBound(Arr_Cate, 2) For Arr_CateNumI = 0 To Arr_CateNumS Debug.Print Arr_Cate(0, Arr_CateNumI) sFile = ThisWorkbook.Path & "" & Arr_Cate(0
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!