View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Harald Staff Harald Staff is offline
external usenet poster
 
Posts: 1,327
Default Message Box Macro

Hi Heather

There are two kinds of msgbox use; you just display it to tell something, or
you ask the user and do different things depending on which response button
the user clicks.

The first kind doesn't use the parentheses (which causes your error) without
Call, syntax is either

Msgbox "Yo!"
or
Call MsgBox("Yo!")

For the response decision you must either put the response into a variable
or decide on the spot. Run this test for different techniques:

Sub test()
Dim L As Long

MsgBox prompt:="Have you saved and closed all other files?", _
Buttons:=vbYesNoCancel, Title:="Check!"

Call MsgBox(prompt:="Have you saved and closed all other files?", _
Buttons:=vbYesNoCancel, Title:="Check!")

L = MsgBox(prompt:="Have you saved and closed all other files?", _
Buttons:=vbYesNoCancel, Title:="Check!")
MsgBox "You replied " & L

Select Case MsgBox(prompt:="Have you saved and closed all other files?", _
Buttons:=vbYesNoCancel, Title:="Check!")
Case vbYes
MsgBox "fine"
Case vbNo
MsgBox "too bad"
Case Else
MsgBox "chicken"
End Select

End Sub

This said, maybe you don't have to ask. Code can find out wether workbooks
are open and saved or not:

Sub AnybodyOutThere()
Dim Wbk As Workbook
For Each Wbk In Application.Workbooks
If Wbk.FullName < ThisWorkbook.FullName Then
If Wbk.Saved = True Then
MsgBox Wbk.Name & " is saved but still open"
Else
MsgBox Wbk.Name & " is open and unsaved"
End If
End If
Next
End Sub

HTH. Best wishes Harald

"Heather O'Malley" skrev i melding
. ..
Hello,

Trying to create a message box -

Titled: check?
Asks the question: Have you saved and closed all other files?
Then gives you a yes, no, cancel choice.

Written the below code but keeps getting a message:

expected :=

MsgBox (prompt:="Have you saved and closed all other files?",
buttons:=vbYesNoCancel, title:="Check!")

Any ideas
Thanks
Heather