PC Review


Reply
Thread Tools Rate Thread

AutoRun Macro with a delay to give user the choice to cancel the macro

 
 
wanderlust
Guest
Posts: n/a
 
      28th Sep 2007
Hi,
I am trying to write a macro that will execute when the workbook
is open. What I intend to do is to run this macro off of a batch file
that will open the file, run the macro and close the workbook.

Ideally, when the batch file kicks off the macro, I would like to
have a message pop up that says "Do you want to run the macro?" with
"yes" and "no" as the options. If there is no response within 10
seconds, go ahead and run the macro. This way, if some user opens the
file, but doesn't want to run the macro, the user can click on "no"
within 10 seconds and cancel the macro execution.

Thanks,
Ravi

 
Reply With Quote
 
 
 
 
Andrew Taylor
Guest
Posts: n/a
 
      28th Sep 2007
You can use the Popup method of the scripting shell object,
which has a timeout parameter.


Sub MessageWithTimeout()
Dim scriptshell As Object

Set scriptshell = CreateObject("wscript.shell")
Const TIMEOUT_SECONDS = 5

Select Case scriptshell.popup("What's the answer?",
TIMEOUT_SECONDS, "Select an answer", vbYesNo + vbQuestion)
Case vbYes
MsgBox "Yes"
Case vbNo
MsgBox "No"
Case -1
MsgBox "Timeout"
End Select

End Sub


On Sep 28, 2:00 pm, wanderlust <rsattul...@gmail.com> wrote:
> Hi,
> I am trying to write a macro that will execute when the workbook
> is open. What I intend to do is to run this macro off of a batch file
> that will open the file, run the macro and close the workbook.
>
> Ideally, when the batch file kicks off the macro, I would like to
> have a message pop up that says "Do you want to run the macro?" with
> "yes" and "no" as the options. If there is no response within 10
> seconds, go ahead and run the macro. This way, if some user opens the
> file, but doesn't want to run the macro, the user can click on "no"
> within 10 seconds and cancel the macro execution.
>
> Thanks,
> Ravi



 
Reply With Quote
 
wanderlust
Guest
Posts: n/a
 
      28th Sep 2007
On Sep 28, 9:39 am, Andrew Taylor <andrew.tay...@cantab.net> wrote:
> You can use the Popup method of the scripting shell object,
> which has a timeout parameter.
>
> Sub MessageWithTimeout()
> Dim scriptshell As Object
>
> Set scriptshell = CreateObject("wscript.shell")
> Const TIMEOUT_SECONDS = 5
>
> Select Case scriptshell.popup("What's the answer?",
> TIMEOUT_SECONDS, "Select an answer", vbYesNo + vbQuestion)
> Case vbYes
> MsgBox "Yes"
> Case vbNo
> MsgBox "No"
> Case -1
> MsgBox "Timeout"
> End Select
>
> End Sub
>
> On Sep 28, 2:00 pm, wanderlust <rsattul...@gmail.com> wrote:
>
> > Hi,
> > I am trying to write a macro that will execute when the workbook
> > is open. What I intend to do is to run this macro off of a batch file
> > that will open the file, run the macro and close the workbook.

>
> > Ideally, when the batch file kicks off the macro, I would like to
> > have a message pop up that says "Do you want to run the macro?" with
> > "yes" and "no" as the options. If there is no response within 10
> > seconds, go ahead and run the macro. This way, if some user opens the
> > file, but doesn't want to run the macro, the user can click on "no"
> > within 10 seconds and cancel the macro execution.

>
> > Thanks,
> > Ravi


Worked like a Charm!!!!!!
Thanks for your help. I was trying to search on the groups for this
but, without success.
Ravi

 
Reply With Quote
 
New Member
Join Date: Oct 2011
Posts: 1
 
      20th Oct 2011
I am trying to do something similar and came across this. Where did you put this script? in a batch file? or in excel's VBA?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you give a user the choice of printer Darren Microsoft Excel Programming 1 2nd Jul 2008 04:06 AM
Start Macro after user selects a choice from a pick list =?Utf-8?B?TWF0aGV3?= Microsoft Excel Misc 2 17th Aug 2006 03:28 PM
How do I give the user a File Open dialog on transferText macro? =?Utf-8?B?USBKb2huc29u?= Microsoft Access Macros 1 9th May 2006 10:57 PM
Cancel Macro is user selects 'cancel' at save menu =?Utf-8?B?TWFyaw==?= Microsoft Excel Programming 1 6th Apr 2005 05:45 PM
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet wyndman Microsoft Excel Programming 2 25th May 2004 06:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.