MSG BOX through macro

  • Thread starter Thread starter XCESIV
  • Start date Start date
X

XCESIV

I would like to setup the macro to confirm they want the macro to b
performed. Can someone please help with this

The macro will be assigned to a push button on the worksheet, once th
report is complete they push the button and then i want it to create
pop up asking "do you wish to close this report YES/NO"
if yes then peform close, if not do nothing.

thank
 
Answer = MsgBox("Would You Like To Close The Workbook?", vbYesNo)
If Answer = vbYes Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else:
Cells.Select
 
XCESIV, here is a general macro that shows a message box with yes, no, and
cancel options, just change to fit your needs

Sub Message_box_test()
Dim Msg, Title, Response As String
Msg = "Put message here"
Title = "Put title here"
Response = MsgBox(Msg, vbYesNoCancel + vbQuestion, Title)

If Response = vbNo Then
'your code if no is clicked here
MsgBox "you clicked no"
Exit Sub ' Quit the macro
End If

If Response = vbCancel Then
'your code if Cancel is clicked here
MsgBox "You clicked cancelled"
Exit Sub ' Quit the macro
End If

'your code if Yes is clicked here
MsgBox "you clicked yes"
End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
Sub myMacro()
Dim ans As Long
ans = MsgBox("Continue?",vbYesNo)
If ans = vbNo Then Exit Sub
' rest of code
End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)
 
You could adapt this

Select Case MsgBox("cntr=" & RecentCntr & " " _
& Application.RecentFiles(RecentCntr).Name _
& vbNewLine & "Delete?", vbYesNoCancel + vbDefaultButton2)
Case vbCancel
GoTo endpgm
Case vbYes
Application.RecentFiles(RecentCntr).Delete
MsgBox "File deleted from recent files list"
Case vbNo
' Do nothing
Case Else
' Do nothin
End Select
 
sub example1

answer = msgbox ("Do you wish to close thi
report?",vbYesNo,Title:="Just to Confirm")

if answer=vbyes then activeworkbook.close

end su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top