+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Forum Contributor
    Join Date
    08-01-2007
    Posts
    111

    Basic macro syntax error. What is wrong?

    Hi there Everyone. My problem probaly it is very easy for some of you but for me its really annoying and makes me go crazy. I just started learning VBA from a book. The title of the book is: "Excel 2003 power programming with VBA" and the author is John Walkenbach. My excel is version 2000, Hungarian version but when I switch to Visual Basic it is English (Visual Basic is always English, right?). So the very first macro in this book is a very basic and simple macro, however I get an error message saying: "Syntax error".

    The macro looks like this:

    Code:
    Sub Test()
    	Sum = 1 + 1
    	MsgBox “The answer is “ & Sum
    End Sub
    The syntax error message I get is referring to the row: MsgBox “The answer is “ & Sum

    Could someone please help me, because I am really frustrated that this is the very first and very basic (I just copy and paste) code and I am already stucked with it, because of this error message. What am I doing wrong? What is wrong?
    Thank you in advance for your help!
    Last edited by hunsnowboarder; 07-16-2008 at 04:23 AM. Reason: Wrong format

  2. #2
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207
    Hi hunsnowboarder,

    VBA can be really frustrating when you first start.

    The problem with your code is the “ characters around the words “The answer is.“

    If you change them to the more 'vertical version' like this: " then your code will be fine provided that there is no Option Explicit statement at the top of your code module.

    This is what your procedure should look like:
    Code:
    Sub Test()
    	Sum = 1 + 1
    	MsgBox "The answer is " & Sum
    End Sub
    Colin

  3. #3
    Forum Contributor
    Join Date
    08-01-2007
    Posts
    111
    Thanx a lot colin_l!!! Now it works!! You cannot imagine how sad and desperate I was that my very first (copy and paste) code did not work!

    Thank you again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0