I need procedure to my codes after click button from the second time

Omar M

New Member
Joined
Jan 11, 2024
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
Hi Experts,
I have code ,running the code from the first time but if I click the button again then should call
sub macro1() before running my original code is sub test().
every time save and close the file.
the first time when run my original code will be when open the file .
I hope this clear guys.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Declare a module level variable (right at the top of the module, something like Dim bolRan As Boolean).
In your 1st sub near the beginning, test bolRan. If it is false, run first sub. If True, call 2nd sub which will then run. Then execution will continue in 1st sub. I suspect that is what you want. In 1st sub just before it will finish or exit, put bolRan = True. Thus when 1st sub runs first time, bolRan becomes True. Upon second button click, 2nd sub will be called from first sub because bolRan is True.

Next time you open wb, bolRan will be false before first click of command button.
 
Upvote 0
Hi
thanks for guiding me.
to be honest I have no idea to that. I have no expriene to write some lines by vba.
I hope to do that for me if you have free time.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,012
Members
449,613
Latest member
MedDash99

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