Macro execution: Start from VBA Editor(F5) vs. Start from Custom ribbon

Vinci2504

New Member
Joined
Jan 13, 2020
Messages
7
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. Mobile
  3. Web
Hi Everyone,

I have prepared some macro saved in local AddIns file. Function is available via button on custom ribbon.

I observed some discrepanciesin code time execution. Between code Option 1 and code Option 2 is small difference in IRibbonControl Sub: MacroTest / Call MacroTest.

But I observed a big discrepanciesin in time between two method on code start :
  • Start from level VBA Editor: Sub MacroTest (column Start from VBA Editor (F_5) )
  • Start from Custom Ribbon Button
Has anyone observed similar results in their code?
I am really interesting why is that difference between code running dirrectly from VBA Editor vs. code running via button in Custom Ribbon.

I also wonder why sometimes I get times at ~1.3s and ~5.5 and at other times times at ~0.4 and ~1.6.
In all testing no conditions has been changed:
  • AddIns installed from local Excel default folder,
  • File always opened from local location and the same folder.
I will be grateful for any suggestions.

Code Option 1
VBA Code:
Sub MacroCustomRibbon(control As IRibbonControl)
    MacroTest
End Sub

Sub MacroTest()

'Delaration of variables, arrays
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    clock = Timer

    'code: operation on Arrays
    'code: operation on worksheet

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Debug.Print Round(Timer - clock, 3)
End Sub

Code Option 2
VBA Code:
Sub MacroCustomRibbon(control As IRibbonControl)
    [B]call [/B]MacroTest
End Sub

Sub MacroTest()

'Delaration of variables, arrays
   
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
   
    'code: operation on Arrays
    'code: operation on worksheet

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Debug.Print Round(Timer - clock, 3)
End Sub



Code running first time in day:
OptionStart from
VBA Editor (F5)
Start from
Custom Ribbon Button
Custom Ribbon Button /
VBA Editor (F5)
Option 1
1.305
17.781
13.63
Option 11.30918.2613.95
Option 11.30518.0713.85
Option 21.3115.4544.16
Option 21.3115.5624.24
Option 21.335.8334.39


Code running other time in day (for example after 1 hour):
OptionStart from
VBA Editor (F5)
Start from
Custom Ribbon Button
Custom Ribbon Button /
VBA Editor (F5)
Option 1
0.398
1.621
4.07
Option 10.4021.593.96
Option 10.3981.563.92
Option 20.4021.6254.04
Option 20.4221.6023.80
Option 20.481.733.60
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,936
Messages
6,181,850
Members
453,068
Latest member
DCD1872

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top