#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.misc
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



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Message Box Macro

Hi Heather,

Just delete the parentheses.

Ken Johnson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 122
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
Row Expansion Susan Excel Worksheet Functions 11 February 28th 06 07:15 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Macro message box ynissel Excel Discussion (Misc queries) 7 July 18th 05 06:50 PM
Macro - message box if find nothing Frantic Excel-er Excel Discussion (Misc queries) 8 July 1st 05 08:45 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"