Molecular states are defined by the molecule's modes of vibration and rotation. These vibrational and rotational modes are quantized, similar to the atomic orbitals, and may be excited by absorbing single photons.
In both the atomic and molecular cases, the excited states do not persist: after some random amount of time, the atoms and molecules revert back to their original, lower energy state. In atoms, the excited electron returns to a lower orbital, emitting a photon. In molecules, the vibrational or rotational mode decays, also emitting a photon.
When this decay occurs, the photon produced is not necessarily emitted in the same direction as the original photon. The most common angle of this has been shown to be about 45 degrees of the original photon. This applies to any situation where gases lie between a light source and an observer: the observer will see gaps in the spectrum of the light corresponding to the wavelengths of the photons which were absorbed. These gaps occur despite the re-emission of photons because the re-emitted photons are equally likely to travel in all directions, and it is statistically unlikely to travel along the original path to the observer. These gaps appear as black lines in an image of the spectrum.