Forum Discussion
Complie error Expected: end of statement
- Apr 01, 2018
I don't see anything wrong with your syntax. Guessing you had some other code in this module that was causing your issue:
Sub GuessName() Msg = "Is your name " & Application.UserName & "?" Ans = MsgBox(Msg, vbYesNo) If Ans = vbNo Then MsgBox "Oh, never mind." If Ans = vbYes Then MsgBox "I must be psychic!" End SubIf your new to VBA, then maybe it will be helpful to know the different arguments associated with MsgBox. Some of the arguments like Button and Title can make your VBA solution more polished looking and allows for greater customization.
Check the MsgBox arguments out here:
https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/msgbox-function
I don't see anything wrong with your syntax. Guessing you had some other code in this module that was causing your issue:
Sub GuessName()
Msg = "Is your name " & Application.UserName & "?"
Ans = MsgBox(Msg, vbYesNo)
If Ans = vbNo Then MsgBox "Oh, never mind."
If Ans = vbYes Then MsgBox "I must be psychic!"
End Sub
If your new to VBA, then maybe it will be helpful to know the different arguments associated with MsgBox. Some of the arguments like Button and Title can make your VBA solution more polished looking and allows for greater customization.
Check the MsgBox arguments out here:
https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/msgbox-function
Thank you so much for your time and tips! I figured out later the issue was caused by the format of "", as I have copied the code from a textbook. Thank you for sending me the link of MsgBox arguments!