ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   add a warning before running a macro (https://www.excelbanter.com/excel-discussion-misc-queries/237008-add-warning-before-running-macro.html)

Picman

add a warning before running a macro
 
i have recorded a macro that clears the contents of the unprotected unlock
cells. i would like to have a message asking if the user is sure that they
want to clear the contents or not to. is this possible?

Dave Peterson

add a warning before running a macro
 
Option Explicit
Sub YourMacHere()
Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if

'rest of your code
End Sub



Picman wrote:

i have recorded a macro that clears the contents of the unprotected unlock
cells. i would like to have a message asking if the user is sure that they
want to clear the contents or not to. is this possible?


--

Dave Peterson

Picman

add a warning before running a macro
 
thanks Dave, sorry i'm not all that experienced with these kinds of
modifications, how would i implement your code?

"Dave Peterson" wrote:

Option Explicit
Sub YourMacHere()
Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if

'rest of your code
End Sub



Picman wrote:

i have recorded a macro that clears the contents of the unprotected unlock
cells. i would like to have a message asking if the user is sure that they
want to clear the contents or not to. is this possible?


--

Dave Peterson


Dave Peterson

add a warning before running a macro
 
You have existing code for your macro, right?

You'd copy the guts that I wrote and paste it into your procedure--right near
the top, before anything really important.

Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if


Are the only lines you'd want to paste (without those symbols, of course).

Picman wrote:

thanks Dave, sorry i'm not all that experienced with these kinds of
modifications, how would i implement your code?

"Dave Peterson" wrote:

Option Explicit
Sub YourMacHere()
Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if

'rest of your code
End Sub



Picman wrote:

i have recorded a macro that clears the contents of the unprotected unlock
cells. i would like to have a message asking if the user is sure that they
want to clear the contents or not to. is this possible?


--

Dave Peterson


--

Dave Peterson

Picman

add a warning before running a macro
 
That worked perfectly, thanks very much

"Dave Peterson" wrote:

You have existing code for your macro, right?

You'd copy the guts that I wrote and paste it into your procedure--right near
the top, before anything really important.

Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if


Are the only lines you'd want to paste (without those symbols, of course).

Picman wrote:

thanks Dave, sorry i'm not all that experienced with these kinds of
modifications, how would i implement your code?

"Dave Peterson" wrote:

Option Explicit
Sub YourMacHere()
Dim resp as long
resp = msgbox(prompt:="Are you sure?", buttons:=vbyesno)
if resp = vbno then
exit sub
end if

'rest of your code
End Sub



Picman wrote:

i have recorded a macro that clears the contents of the unprotected unlock
cells. i would like to have a message asking if the user is sure that they
want to clear the contents or not to. is this possible?

--

Dave Peterson


--

Dave Peterson



All times are GMT +1. The time now is 06:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com