I think that the concept of "morality" is much too vague for that question to be really meaningful. If we define an immoral act as anything that is counterproductive to the ongoing maintenance of cooperative society, which is as good a definition as any I've heard, then the law is all about legislating morality (indeed, the principle that it is possible to legislate morality becomes a mere tautology), in that a chief goal of the law is (or at least, I think, should be) to prevent precisely those sorts of acts. But different people have different conceptions of the basis and content of morality, and since quite often the people debating the issue of legislating morality have very different notions of what morality is, I think they generally just end up talking past one another.
I suspect, from my own experience, that people who argue that "you can't legislate morality" quite often mean by that statement that it is impossible to persuade other people of the correctness of one's own conception of morality by enacting that conception into law. I think that view is wrong, or at least misguided, for two reasons. First, there's the crossover problem-- the law itself quite often carries some degree of moral force, such that a particular act may be deemed immoral simply because it is illegal. Insofar as that is the case, attitudes about the morality of some specific conduct can certainly be influenced by enacting a law imposing a criminal penalty on that conduct. Second, I think that the objection is misguided because, generally speaking, the purpose of imposing criminal sanctions on some kind of conduct is not, primarily, to persuade the public that the conduct is immoral, but rather, simply to prevent the conduct from taking place. Laws against prostitution and marijuana use, for example, might not persuade some portion of the public that those activities are inherently immoral, but they do prevent a significant portion of individuals who might otherwise engage in such conduct from doing so, and permit the state to punish those individuals who disregard the law and engage in the prohibited conduct anyway. From the perspective of deterrence, it isn't really relevant whether the legal prohibition in question is widely internalized as a moral norm or not, so long as the behavior in question is prevented, or at least substantially curbed, by the operation of the law.
So, in short, to the extent that the question has any clear meaning, it is possible to legislate morality to a significant degree. The questions whether all widely-held moral beliefs should be enacted into law, or whether all legal prohibitions should be regarded as carrying a moral force, are separate and somewhat more complicated questions that are not resolved by the affirmative answer to the question posed in the opening post.