优化代码:Option ExplicitPrivate Declare Function MsgBoxEx Lib user32 Alias MessageBoxTimeoutA _ByVal hWnd As Long ByVal lpText As String ByVal lpCaption As String ByVal _wType As VbMsgBoxStyle ByVal wlang
Option Explicit Private Declare Function MsgBoxEx Lib "user32" Alias "MessageBoxTimeoutA" _ (ByVal hWnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal _ wType As VbMsgBoxStyle, ByVal wlange As Long, ByVal dwTimeout As Long) As Long '声明 Public destinationDatabase As String Public Timestr As String Public TestProName As String Public SourceName As Long '修改时间 Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Private Sub Command1_Click() Call CommandButton2_Click End Sub Private Sub CommandButton2_Click() Dim i As Integer Dim sourcePath As String Dim NewName As String Dim destinationPath As String Dim sourceDatabase As String Dim db As DAO.Database
sourcePath = "E:\检测设备\压力试验机\新vba\"
destinationPath = "E:\检测设备\压力试验机\新vba\"
' 创建Excel对象
Dim excelApp As New Excel.Application
' 打开Excel文件
Dim workbook As Excel.workbook
Set workbook = excelApp.Workbooks.Open("E:\检测设备\压力试验机\新vba\test.xlsm")
' 获取第一个工作表
Dim worksheet As Excel.worksheet
Set worksheet = workbook.Sheets(1)
'计算表格中有多少行
Dim lastRow As Long
lastRow = worksheet.Range("A" & worksheet.Rows.Count).End(xlUp).Row
For i = 1 To lastRow - 1
'Call Sys_TimeChange(i + 1)
SourceName = worksheet.Range("C" & i + 1).Value
NewName = worksheet.Range("A" & i + 1).Value
Timestr = worksheet.Range("B" & i + 1).Value
TestProName = "粗集料压碎值" & "(" & SourceName & "kN)"
sourceDatabase = SourceName & ".mdb"
destinationDatabase = NewName & ".mdb"
'MsgBox destinationDatabase
FileCopy sourcePath & sourceDatabase, destinationPath & destinationDatabase
Set db = OpenDatabase(destinationPath & destinationDatabase)
'Call CommandOriginalData 'OriginalData
'Application.Wait Now + TimeValue("0:00:01") '延时1秒
'Call CommandTestNo 'TestNo
'Application.Wait Now + TimeValue("0:00:01")
'Call CommandParamFactValue 'ParamFactValue
'Application.Wait Now + TimeValue("0:00:01")
'Call CommandTestNoParam 'TestNoParam
'Application.Wait Now + TimeValue("0:00:01")
db.Close
worksheet.Range("H7").Value = worksheet.Range("H7").Value + 3
MsgBoxEx 0, "已完成第" & i & "个任务", "恒信云", vbYesNo + vbInformation, 1, 500
Next i
MsgBox "结束啦,项目已完成!"
End Su
原文地址: http://www.cveoy.top/t/topic/iDaP 著作权归作者所有。请勿转载和采集!