\documentclass{article}
\begin{document}
% Sample from the LaTeX Companion:
\newcounter{excnt}[section]
\renewcommand\theexcnt{\thesection.\Alph{excnt}}
\newenvironment{EX}{\begin{flushleft}%
\refstepcounter{excnt}%
\textbf{Exercise~\theexcnt:}}%
{\end{flushleft}}
\setcounter{section}{4} % just for testing
\section{A Success}
\begin{EX} \label{ex:A} A test text. \end{EX}
\begin{EX} \label{ex:B} Another test text. \end{EX}
\noindent Referencing exercises with {\tt\string\newenvironment}: \ref
{ex:A} and \ref{ex:B}.
% \NewEnviron failed to give the correct references:
\NewEnviron{EXC}{%
\begin{flushleft}%
\refstepcounter{excnt}%
\textbf{Exercise~\theexcnt:}%
\end{flushleft}%
}
\section{A Failure}
\begin{EXC} \label{exc:A} A test text. \end{EXC}
\begin{EXC} \label{exc:B} Another test text. \end{EXC}
\noindent Referencing exercises using {\tt\string\NewEnviron}: \ref
{exc:A} and \ref{exc:B}.
\end{document}
> \NewEnviron{EXC}{%
> \begin{flushleft}%
> \refstepcounter{excnt}%
> \textbf{Exercise~\theexcnt:}%
> \end{flushleft}%
> }
You're missing "\BODY".
W