The rules on commas with quotes can be confusing. I hope these explanations and examples will clarify the rules.
Use a comma with a verb of saying. A verb of saying is, well, any verb that is synonymous with say, such as tell, shout, whisper, utter, state, reply, indicate, answer. If you're not sure whether it's a verb of saying, replace the verb with say or say to (and conjugate it, of course) and see if the sentence retains its meaning. If it does retain the meaning, then it's a verb of saying. Consider these examples and their tests for correctness:
When the coach orders, "Go," start dribbling down the court.
Test: When the coach says, "Go," start dribbling down the court.
Tell the students, "Stand on the white line."
Test: Say to the students, "Stand on the white line."
"I promised I would," I replied.
Test: "I promised I would," I said.
"No," he said, "but you can always hope."
Here are some other rules regarding commas with quote marks:
When a quotation other than actual dialogue serves as the subject or object or complement of a verb that's not a verb of saying, omit the comma:
"Sorry" doesn't help, but try "I'll make it up to you."
On a related note, don't use a comma if the quoted part is simply functioning as the object in the sentence:
When someone exhibits honest enthusiasm, praise her with "Yes! That's the way we do things on this team!"
Here's an exception to the comma-with-verb-of-saying rule: Don't use quotes or commas with verbs of saying when it involves an often-used one-word statement, such as yes, no, or salutations (CMS 5.202):
If you answered no to the previous questions, continue to the next part of the survey.
Say hi to Mona for me.
He left without saying good-bye.
Don't use a word that isn't synonymous with say in place of say:
Bad: "I'd like to think so," he smiled.
Good: "I'd like to think so," he said with a smile.