|
请大佬看看下面程序,能否优化一下,从(YHGC20230342024.3.20 HXL V1)中的品号汇总表点击导入数据(新编码规则物料表2024.3.27.xlsm)导入数据时间太长。
下面是导入数据的VBA程序
Private Sub CommandButton1_Click()
Dim dict As String
Dim file As String
Dim filename As String
Dim name As String
Dim Sht As Excel.Worksheet
Dim dataExcel, Workbook, Sheet
Dim totalRow As Integer
Dim totalColumn
Dim i%, j%, MaxRow%
'Dim Arr1
Dim a()
Dim Sss
On Error Resume Next
dict = Me.Range("L2").Value
file = Me.Range("L3").Value
filename = dict & "\" & file
'Workbooks.Open "'" & filename & "'"
name = "'" & filename & "'!汇总"
'Application.Run name 'Application.Run "abc.xlsm!Sheet1.
Set dataExcel = CreateObject("Excel.Application")
Set Workbook = dataExcel.Workbooks.Open(dict & "\" & file)
Set Sheet = Workbook.Worksheets("总表") '读取第一个sheet页的数据
'Arr1 = Sheet.UsedRange
MaxRow = Sheet.Range("C3").End(xlDown).Row
Sss = Sheet.Range("A3:L" & MaxRow)
Workbook.Close
Sheets("品号汇总表").Active
'Application.ScreenUpdating = False
For i = 1 To MaxRow - 2
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 1) = Sss(i, 1) '序号
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 2) = Sss(i, 2) '品号
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 3) = Sss(i, 3) '物料名称’
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 4) = Sss(i, 4) '规格型号’
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 5) = Sss(i, 5) '单位
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 6) = Sss(i, 6) '申请人
'Sheets("品号汇总表").Cells(i + 4,7) = arr(3, 1) '厂商名称
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 8) = Sss(i, 8) '备注
ActiveWorkbook.Sheets("品号汇总表").Cells(i + 4, 9) = Sss(i, 9) '其他
Next i
'Application.ScreenUpdating = True
MsgBox "读取成功!", vbSystemModal, "导入数据" & name '读取完后弹框提醒
ActiveWindow.ScrollRow = 1
Application.StatusBar = "更新时间: " & Date & Time
End Sub
|
|