|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub demo()
- Dim conn As Object, connectionStr$, sqlStr$
- Set conn = CreateObject("Adodb.Connection")
- connectionStr = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='excel 12.0;HDR=YES';Data Source=" & ThisWorkbook.FullName
- conn.Open connectionStr
-
- sqlStr = "SELECT" & _
- " '' AS 司機," & _
- " '' AS 跟車," & _
- " '' AS 車牌," & _
- " '' AS 客戶," & _
- " '' AS 取貨點," & _
- " A.收货公司名称 AS 送貨點," & _
- " B.地區," & _
- " (CSTR(A.[出货数量-托盘])+'板') AS 板," & _
- " '' AS 箱," & _
- " (CSTR(A.毛重KG)+'kg') AS 重量," & _
- " '' AS BM," & _
- " A.发票号 AS 單號," & _
- " A.特殊派送要求 AS [時間要求/注意事項]," & _
- " ''," & _
- " IIF(A.收货公司名称='德迅空','拆板,按箱交货','') AS 特別收費,"
- sqlStr = sqlStr & _
- " '' AS OB," & _
- " (FORMAT(NOW,'m/dd')+' '+ A.香港车牌) AS 中港車牌," & _
- " '' AS 代墊雜費," & _
- " ''," & _
- " A.车次," & _
- " A.大陆车牌 " & _
- "FROM" & _
- " [1.仓库整理$] A," & _
- " (SELECT DISTINCT A1.收货公司名称,A2.地區 FROM [1.仓库整理$] A1 LEFT JOIN [地区V$] A2 ON A1.收货公司名称=A2.收貨人) B " & _
- "WHERE" & _
- " A.收货公司名称=B.收货公司名称"
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Dim useRange As Range
-
- With ThisWorkbook.Worksheets.Add(after:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count))
- .Name = "生成模板" & Format(Now, "yymmddhhmmss")
- .Range("c3").CopyFromRecordset conn.Execute(sqlStr)
- .Range("c2:w2").Value = Array("司機", "跟車", "車牌", "客戶", "取貨點", "送貨點", "地區", "板", "箱", "重量", " BM", "單號", "時間要求/注意事項", "時間要求/注意事項", "特別收費", "OB", "中港車牌", "代墊雜費", "", "", "")
- .Range("e1").Value = "L每日派送"
- .Range("l1:m1").Value = Array("日期:", Format(Date + 1, "yyyy/mm/dd"))
- Set useRange = Application.Intersect(.UsedRange, .Range("2:1048576"))
- End With
- With useRange
- .Borders.Weight = xlThin
- .Borders.LineStyle = xlContinuous
- .Borders.ColorIndex = xlColorIndexAutomatic
- .HorizontalAlignment = xlHAlignLeft
- .VerticalAlignment = xlVAlignCenter
- .Font.Name = "微软雅黑"
- .Font.Size = 10
- .Font.Bold = True
- .Columns.AutoFit
- End With
- conn.Close
- Set conn = Nothing
-
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|