我有VBA中的代碼和大量的行使用太多的內存 - 它可能需要幾GB,並使粉碎。代碼數量請求服務器爲XLM查找一些數據並寫入它們而不是轉到另一個數字。如果超過500行,它會粉碎。你能幫我優化代碼來處理大約10000行嗎? 感謝您的幫助 馬立克VBA代碼優化
Sub ares()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False 'potlačí obnovování obrazovky
Application.DisplayAlerts = False 'potlačí varovné hlášky
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Dim i As Integer
Dim row As Integer
Dim column As Integer
For i = 2 To 15000
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "ares"
Sheets("ares").Activate
On Error GoTo ErrorHandler
ActiveWorkbook.XmlImport URL:="http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi?ico=" & Worksheets("ico").Cells(i, 1).Value, ImportMap:=Nothing, Overwrite:=True, Destination:=Range("$A$1")
If Worksheets("ares").Cells(2, 10).Value = "" Then
Worksheets("ico").Cells(i, 2).Value = "OK"
row = 2
column = 3
Do While Worksheets("ares").Cells(row, 1).Value <> ""
If Worksheets("ares").Cells(row, 167).Value <> "" Then
Worksheets("ico").Cells(i, column).Value = Worksheets("ares").Cells(row, 167).Value
column = column + 1
End If
row = row + 1
Loop
Else
Worksheets("ico").Cells(i, 2).Value = Worksheets("ares").Cells(2, 10).Value
End If
ErrorResume:
Sheets("ares").Delete
Next i
Application.ScreenUpdating = True 'zapne obnovování obrazovky
Application.DisplayAlerts = FaTruelse 'obnoví varovné hlášky
Application.Calculation = xlCalculationAutomatic
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
Exit Sub
ErrorHandler:
Worksheets("ico").Cells(i, 2).Value = "Jiná chyba"
Resume ErrorResume
End Sub
'Application.DisplayAlerts = FaTruelse「obnovívarovnéhlášky' - 這是一個新的布爾:) – Vityata
什麼辦法可以導入數據和設置您的ICO細胞而無需添加和刪除表單的時間。也許重用表單? – MacroMarc