excel vbscript for command button to retry script

cizzett

Board Regular
Joined
Jan 10, 2019
Messages
121
So my workbook has a lot of script in it and I use "Bundles" of script to perform big functions, one such function that resides in a bundle of scripts reaches to SAP through GUI Scripting and pulls data. It is set to use an active window not with hard coded user and password info so if the user does not have an active window open in SAP it will error.

What I would like is when my error handler message opens instead of just using an End to kill the script id like the option for the user to rerun the current script in the bundle.

I am assuming it would simply be part of the script error handler so when it errors if it retry's the script then it doesn't kill the rest of the bundles script that would come after this script ends.

Any Idea on a command to simply restart this script if the user has now opened a window to resolve the issue and not kill anything else allowing it to just continue on as normal if it no longer errors?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
.
You could use the command ON ERROR RESUME NEXT at the beginning of your macro code.
In most circumstances, if an error occurs it will not result in any notification to the USER and simple
progress on with the remainder of the code.

You could use an ERROR HANDLER with a messagebox notification to the USER which, after clicking OK
would return the USER to the beginning of the code again.

Neither of the above results in rectifying the error issue. All it does is sweep it under the rug to rear it's
ugly head again.

I'm not certain how you would return the USER to the error point so the USER could continue from that point.

Here is a good resource on ERROR HANDLING. Perhaps something therein will spur your mind to create
something that works for your needs :

https://excelmacromastery.com/vba-error-handling/
 
Upvote 0
So I was able to simple set a line at the top of the sub routine and reference to it so
Code:
Case vbRetry: GoTo Restart:
and I have Restart: at the top of the sub routine. This works great but if it errors a second time around it goes into debug.

Anyone know of any way to take it back to the error handler from the second time through?
 
Upvote 0
.
One method would be to record when it goes into error the first time. Then check against that the second time around.

Example : When it enter the error handler the first time, record a number 1 somewhere with in the workbook. An example might be on Sheet1 in cell XFD1.
That would place the data FAR away from anything anyone is likely to use, but of course it can be any location that won't be written over by some other action.

Then, when it enter the error handler the second time, include script that basically says

If Range("XFD1").Value = "1" Then
GoTo Another SecondTime:
End If

Place the SecondTime: below the error handler
so the user isn't re-routed back through the code to error a third time. Or, you can include
a MsgBox that indicates "This error has occurred multiple times. Please contact your IT Administrator."
 
Upvote 0
Update I changed to "Resume Restart:" for my yes answer to clear the error now it works perfect
 
Upvote 0
Glad you have an answer.

Cheers.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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