Forum Discussion

enqi.angel.xu's avatar
enqi.angel.xu
Copper Contributor
Mar 31, 2018
Solved

Complie error Expected: end of statement

Hi Everyone,   I just stared learning Excel VBA and I have copied the following code from a VBA book to VBE but it displayed the message: Complie error Expected: end of statement.   Sub Guess...
  • Matt Mickle's avatar
    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 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

     

     

     

     

Resources