我创建了一个宏,它通过下拉列表循环并将文件保存在某个位置。代码工作正常,但我需要保存200多个文件,弹出保存文件的状态栏,整个过程非常慢。我的问题是有没有办法加快这个过程可能会禁用保存状态更新?正如您所看到的,我在任何地方插入Application.Displayalerts = False都无济于事。这是我的代码
Sub File_Generator()
Dim cell As Range
Dim wsSummary As Worksheet
Dim counter As Long
Dim strFilename As String
Dim wbNew As Workbook
Dim wbThis As Workbook
Set wbThis = ThisWorkbook
Set wsSummary = Sheets("Master Plan")
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
For Each cell In Worksheets("Team Breakdown").Range("$C$3:$C$221")
If cell.Value = "" Then
counter = counter + 1
Application.StatusBar = "Processing file: " & counter & "/1042"
Else
'progress in status bar
counter = counter + 1
Application.StatusBar = "Processing file: " & counter & "/1042"
With wsSummary
.Range("$B$2").Value = cell.Value
strFilename = wbThis.Sheets("Master Plan").Range("N1").Value & "\" & cell.Value & " Master Plan"
wsSummary.Copy
Set wbNew = ActiveWorkbook
Application.DisplayAlerts = False
Application.ScreenUpdating = False
wbNew.SaveAs strFilename
Application.DisplayAlerts = False
Application.ScreenUpdating = False
wbNew.Close
Application.DisplayAlerts = False
Application.ScreenUpdating = False
End With
End If
Next cell
Set wbThis = Nothing
Set wsSummary = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub