From ad9b9bdd3976157118fa35bc24d03b7dc7c8ff3f Mon Sep 17 00:00:00 2001 From: xiaochou164 Date: Tue, 15 Aug 2023 19:31:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 拉取电阻信息.vba | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/拉取电阻信息.vba b/拉取电阻信息.vba index d46150e..9023113 100644 --- a/拉取电阻信息.vba +++ b/拉取电阻信息.vba @@ -1,10 +1,11 @@ Sub 拉取电阻信息() -t = Timer +t = Timer ''记录开始运行的时间,方便后续输出运行的时长 -Application.ScreenUpdating = False -Application.Calculation = xlCalculationManual +Application.ScreenUpdating = False ''关闭屏幕更新,加速运行 +Application.Calculation = xlCalculationManual ''设置成手动计算,加速运行 +''从数据库中拉取电阻档位的SQL语句 Sql = "SELECT order_no,resistivity, " Sql = Sql + "case when resistivity LIKE '>%' then SUBSTRING(resistivity,5,7) " Sql = Sql + " when resistivity LIKE '%~%' then SUBSTRING_INDEX(resistivity,'~',1) " @@ -25,23 +26,23 @@ Sql = Sql + " when resistivity LIKE '<%' then SUBSTRING(resistivity,2,7) " Sql = Sql + " when resistivity = '未分档' OR resistivity IS null then '未分档' end " Sql = Sql + " from mes_sync.mes_recycle_material_storage; " - - Call AutoRun '------获取数据库连接 Application.StatusBar = "正在拉取批次信息" RES.Open Sql, conn '-----执行strSql 获得结果集 Application.StatusBar = "正在复制批次信息到表格" -Sheets("电阻信息").Cells(2, 1).CopyFromRecordset RES +Sheets("电阻信息").Cells(2, 1).CopyFromRecordset RES ''将RES结果集中的内容复制到Sheets("电阻信息")的A2单元格 RES.Close '-------关闭结果集 必须要做的 -Call closeConn +Call closeConn ''关闭链接,释放资源 -尾行 = Cells(Rows.Count, "A").End(xlUp).row +尾行 = Cells(Rows.Count, "A").End(xlUp).row ''获取尾行行数 Application.StatusBar = "正在判断高低阻信息" +''下面是判断高低阻的内容,已在sql语句中实现相应功能 + For i = 2 To 尾行 电阻 = Sheets("电阻信息").Cells(i, 3).Value On Error Resume Next @@ -56,13 +57,12 @@ For i = 2 To 尾行 End If Next - - -Application.ScreenUpdating = True -Application.Calculation = xlCalculationAutomatic +Application.ScreenUpdating = True ''运行结束,打开屏幕更新 +Application.Calculation = xlCalculationAutomatic ''运行结束,打开自动计算 Application.StatusBar = "拉取完成" -MsgBox ("本次更新共花费:" & Format(Timer - t, "0.00") & "s!") -Application.StatusBar = False +MsgBox ("本次更新共花费:" & Format(Timer - t, "0.00") & "s!") ''弹窗提示运行时间 +Application.StatusBar = False ''恢复状态栏初始状态 + End Sub