Let $v_1,\dots,v_m$ be a basis of range $T$. If $\dim \text{range }T=\dim W$, this means that a basis of range $T$ is a basis of $W$ as range $T\subset W$ and the basis of range $T$ is a linearly independent list of length $\dim W$ of vectors from $W$ and thus is a basis of $W$. By definition, a basis $w_1,\dots,w_n$ of a vector space $W$ is a linearly independent list of vectors in that vector space such that $\text{span}(w_1,\dots,w_n)=W$. Thus, if a basis of range $T$ is a basis of $W$, then we see that $\text{span}(v_1,\dots,v_m)=\text{range }T=W$. Thus, range $T=W$.
Your second example fails because a basis of $A$ is not a basis of $B$ as $b\not\subset A$.
To properly prove that if $$\dim \text{range }T=\dim W\implies \text{range }T=W$$
first prove that a basis of range $T$ is a basis of $W$(you can use the theorem that any linearly independent list of length $\dim W$ consisting of vectors from $W$ is a basis of $W$). Then just use the definition of a basis of a vector space to conclude that range $T=W$.