|
Sub limonet()
Dim Cn As Object, Rst As Object, StrSQL$, Sht$, M$
Sht = Application.InputBox("请输入销汇或进汇", "工作表名称", "销汇", , , , , 2)
M = Application.InputBox("请输入月份", "工作表名称", 3, , , , , 2)
Set Cn = CreateObject("adodb.connection")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data source=" & ThisWorkbook.FullName
StrSQL = "select * from [" & Sht & "$] where Month(开票日期)=" & M
Worksheets.Add(after:=Worksheets(Sheets.Count)).Name = Sht & M & "月"
Set Rst = Cn.Execute(StrSQL)
For j = 0 To Rst.Fields.Count - 1
Cells(1, j + 1) = Rst.Fields(j).Name
Next j
Range("A2").CopyFromRecordset Rst
Range("A1").CurrentRegion.Columns.AutoFit
Set Cn = Nothing
Set Rst = Nothing
End Sub |
评分
-
1
查看全部评分
-
|