Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default AutoRun Macro with a delay to give user the choice to cancel the macro

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default AutoRun Macro with a delay to give user the choice to cancel the macro

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 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default AutoRun Macro with a delay to give user the choice to cancel the macro

On Sep 28, 9:39 am, Andrew Taylor 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 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Start Macro after user selects a choice from a pick list mathew Excel Discussion (Misc queries) 2 August 17th 06 03:28 PM
Cancel Macro is user selects 'cancel' at save menu Mark Excel Programming 1 April 6th 05 05:45 PM
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet wyndman Excel Programming 2 May 25th 04 06:59 PM
Autorun a macro Nigel Chapman Excel Programming 1 February 4th 04 01:02 PM
Autorun a macro No Name Excel Programming 2 November 21st 03 09:26 PM


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"