Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Answer a msgbox yesno with a macro?

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Why have it pop up at all, why not replace the msgbox with:

    Code:
    With ThisWorkbook
        .Save
        .Close
    End With
    _________________
    Cheers, NateO

    [ This Message was edited by: NateO on 2002-04-25 16:02 ]

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  5. #5
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Might want to give post #2 in this thread a look see:

    http://www.mrexcel.com/board/viewtop...c=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, NateO

    [ This Message was edited by: NateO on 2002-04-25 17:06 ]

  6. #6
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.

  7. #7
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    did you see my post. where respose is = to the msgbox answer?

  8. #8
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  9. #9
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    OK.
    so at the moment with your code it IS NOT exporting to a text file... correct?

  10. #10
    Board Regular
    Join Date
    Mar 2002
    Location
    Sydney/Brisbane , Australia
    Posts
    542
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •