我有一个非常基本的VBA脚本,可以保存报告副本,刷新SQL数据连接,调整列宽并重新保存文件。由于某种原因,在保存文件之前,我发现的所有选项都无法充分暂停计算。
Sub SaveAs()
ActiveWorkbook.SaveAs ActiveWorkbook.Path & "\" & "Dep - " & _
Format(Date, "YYYYMMDD") & ".xlsm" _
ActiveWorkbook.RefreshAll
Columns("B:N").Select
Range("B37").Activate
Columns("B:N").EntireColumn.AutoFit
Application.Calculate
ActiveWorkbook.Save
End Sub
Sub Button()
Call SaveAs 'Macro1
End Sub
我尝试了几种方法来延迟它,但似乎都没有作用
'Option 1
Application.Calculate
Application.Calculation = xlManual
Application.CalculateBeforeSave = True
'Option 2
Do While Application.CalculationState <> xlDone
Application.Calculate
Loop
'Option 3
Application.Calculate
Application.Wait Now + TimeValue("00:00:30")
'Option 4
Application.Calculate
If Application.CalculationState = xlDone Then
DoEvents
End If
ActiveWorkbook.Save
知道我缺少什么吗?
谢谢。