0

I have a excel report with VBA code. It generally runs within 1 minute if no other application opened. Excel report runs become 2 minutes if outlook opened. Excel reports runs become 6 minutes if outlook,chrome and bloomberg terminal application opened.

The excel report VBA code has been optimized. But it still running slow when other application opend. More application opened can make excel report more slow.

Is there anybody can help me solve this issue? Thanks in advance.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Deep in Development
  • 497
  • 2
  • 8
  • 24
  • Interesting. Wouldn't it just be a matter of performance backdrop due to more memory used for these other applications, meaning less memory to run a macro? Whether they are idle or not, they still use memory I suppose. – JvdV Jul 30 '19 at 14:45
  • @JvdV Win10, 16GB RAM, SSD, Excel 2016 32Bit – Deep in Development Jul 30 '19 at 14:59
  • @Dorian Thanks for your provided. Actually, code has been optimized. But the issue is still there. If we just run the report, it runs fast. The report runs slow when there are some others applications opened. It seems like excel always get low priority when it runs with other apps. But even I set excel priority to high at run time. It does not take any improved. Any suggestion to it? – Deep in Development Jul 30 '19 at 16:25
  • @DeepinDevelopment maybe set as low or normal all other applications and see what happen .. – TourEiffel Jul 30 '19 at 16:28
  • And maybe set excel as realtime priority but you will not need to be able to alocate more than 50% of your cpu.. you can also try to split your macro in order to use multi-core ... if you got several core processing – TourEiffel Jul 30 '19 at 16:30
  • @Dorian System does not allowed set to realtime – Deep in Development Jul 30 '19 at 18:29
  • @DeepinDevelopment If your issue is solved, may I ask you to accept [this answer](https://stackoverflow.com/a/57275420/11167163) – TourEiffel Sep 26 '19 at 09:26

2 Answers2

0

1) A simple solution could be going into task manager and adding a higher CPU priority to Excel.

2) If your VBA is writing values in a excel sheet that has calculations in it, you might want to look into turning off automatic spreadsheet calculations.

0

There might be a lot of factors contributing to this issue:

  1. Any actions triggered in these events:

    Worksheet_Calculate()

    Worksheet_Change()

    Worksheet_FollowHyperlink()

    Worksheet_SelectionChange()

    Workbook_SheetCalculate()

    Workbook_SheetChange()

    Workbook_SheetFollowHyperlink()

  2. external links, and the external file(s) moved or deleted

  3. database connections (check Data Tab -> Connections) (doubtful)

  4. Invalid Named Ranges (Formula Tab -> Name Manager; any Refs?)

  5. Data validation rules (Data Tab -> Data Validation -> clear all)

  6. Are you opening the file from a network location - this will make it much slower

  7. Conditional Formatting rules? - remove all

  8. Any hidden objects? (Alt + F10 - delete all)

  9. Hidden formatting (what is the last used cell with data?)

  10. Corrupt file

If the file is corrupt, and it's feasible, try re-creating it from scratch, and run this function first

  1. If it's not corrupt, one of the first things I'd try is to disable all Excel

functionality before the macro:

Sub MainSubTryMe()

    'UnlockSettingsWorksheet

    FastWB          '<--- Disables all Application and Worksheet level settings

    'YOURCODE HERE

    XlResetSettings '<--- Restores all Excel settings to defaults

    'LockSettingsWorksheet

End Sub


Public Sub FastWB(Optional ByVal opt As Boolean = True)
    With Application
        .Calculation = IIf(opt, xlCalculationManual, xlCalculationAutomatic)
        .DisplayAlerts = Not opt
        .DisplayStatusBar = Not opt
        .EnableAnimations = Not opt
        .EnableEvents = Not opt
        .ScreenUpdating = Not opt
    End With
    FastWS , opt
End Sub

Public Sub FastWS(Optional ByVal ws As Worksheet, Optional ByVal opt As Boolean = True)
    If ws Is Nothing Then
        For Each ws In Application.ThisWorkbook.Sheets
            OptimiseWS ws, opt
        Next
    Else
        OptimiseWS ws, opt
    End If
End Sub

Public Sub OptimiseWS(ByVal ws As Worksheet, ByVal opt As Boolean)
    With ws
        .DisplayPageBreaks = False
        .EnableCalculation = Not opt
        .EnableFormatConditionsCalculation = Not opt
        .EnablePivotTable = Not opt
    End With
End Sub
Public Sub XlResetSettings()    'default Excel settings
    With Application
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
        .DisplayStatusBar = True
        .EnableAnimations = False
        .EnableEvents = True
        .ScreenUpdating = True
        Dim ws As Worksheet
        For Each ws In Application.ThisWorkbook.Sheets
            With ws
                .DisplayPageBreaks = False
                .EnableCalculation = True
                .EnableFormatConditionsCalculation = True
                .EnablePivotTable = True
            End With
        Next
    End With
End Sub

Maybe this will eliminate some VBA causes

You Can also Have a look here :

Improving calculation performance

Performance and limit improvements

Tips for optimizing performance obstructions

An other Stack Answer

TourEiffel
  • 4,034
  • 2
  • 16
  • 45