Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
Message Box Macro
Hi Heather,
Just delete the parentheses. Ken Johnson |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to stop Excel remembering/loading macro from previously opened Workbook | Excel Discussion (Misc queries) | |||
Row Expansion | Excel Worksheet Functions | |||
Closing File Error | Excel Discussion (Misc queries) | |||
Macro message box | Excel Discussion (Misc queries) | |||
Macro - message box if find nothing | Excel Discussion (Misc queries) |