ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Message Box Macro (https://www.excelbanter.com/excel-discussion-misc-queries/100528-message-box-macro.html)

Heather O'Malley

Message Box Macro
 
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

Harald Staff

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




Ken Johnson

Message Box Macro
 
Hi Heather,

Just delete the parentheses.

Ken Johnson


Melissa

Message Box Macro
 
Hi!
I'm completely new to VB. I just want a simple message box to appear when
my workbook is opened. Where do I even start to create this box? Tools
Macros Visual Basic Editor ???

Thanks!

"Harald Staff" wrote:

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






All times are GMT +1. The time now is 04:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com