Answer a msgbox yesno with a macro?

robfo0

Active Member
Joined
Feb 19, 2002
Messages
281
Hi everyone,

I have a file that has a shutdown after certain amount of time macro. this works fine, but , on the before_close event, i have this code:

msgbox("Save?",vbyesno)

so this question comes up preventing the shutdown from doing its thing (save, and shutdown).

Is there a way to get the shutdown macro to answer vbyes to this question when it pops up?

Thanks :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Why have it pop up at all, why not replace the msgbox with:

Code:
With ThisWorkbook
    .Save
    .Close
End With

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-25 16:02
 
Upvote 0
Nate, if i do that, the message will still come up (i use the before close method). I need this message to come up for other reasons (im using a text export on close), it IS needed. So is there a way to answer the msgbox with the shutdown macro?

Thanks
 
Upvote 0
Response = MsgBox ("save")
If Response = vbYes Then' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If
 
Upvote 0
Might want to give post #2 in this thread a look see:

http://www.mrexcel.com/board/viewtopic.php?topic=2215&forum=2

Where you see 'your code here, call a macro or insert your code.

I don't exactly follow you though, even with the before close method, if you save and close immediately, you shouldn't get the prompt. Maybe under vbno (or vbyes) you go this direction and under the other scenario you do some messages. There's no need to write a macro that clicks a button if you want it to perform the underlying procedure, just need to write the procedure...
_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue">O</font></font></font>
This message was edited by NateO on 2002-04-25 17:06
 
Upvote 0
Nate, i have the code in the before close as i explained to ask the user if they wnat to save changes. this is neccessary because i an using the before close to export information to a text file. if i dont ask the question, the information will be exported whether the user wants to export it or not.

The code of my shutdown after 12 min macro has this code:

Sub ShutDown()
ThisWorkbook.Save
ThisWorkbook.Close
End Sub

but on close, it runs the question that i am asking, as it should.

so i need the macro to answer yes to the msgbox question to correctly export the text file.

I guess i could put the whole export code into the shutdown code, but that would be redundant wouldnt it? any ideas? let me know if i still need to explain more.
 
Upvote 0
Qroozn, yes, but i think im missing something...i have the code very similar to that, but how does "Response" get a vbyes or vbno without the user selecting one? Im trying to accomplish this purely with a macro. The user will not be selecting anything (im trying to make this an auto file save and shutdown after 12 min of inactivity)

did i miss something?

thanks
 
Upvote 0
OK.
so at the moment with your code it IS NOT exporting to a text file... correct?
 
Upvote 0
why dont you change the

msgbox("Save?",vbyesno)
to
call exporttotextfile 'your export macro
'where this code is the code to export your info.

and then the save and close routine
 
Upvote 0

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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