In this work we consider time dependent quasiperiodic perturbations of autonomous Hamiltonian systems. We focus on the effect that this kind of perturbations has on lower dimensional invariant tori. Our results show that, under standard conditions of analyticity, nondegeneracy and nonresonance, most of these tori survive, adding the frequencies of the perturbation to the ones they already have. The paper also contains estimates on the amount of surviving tori. The worst situation happens when the initial tori are normally elliptic. In this case, a torus (identified by the vector of intrinsic frequencies) can be continued with respect to a perturbative parameter $\epsilon\in[0,\epsilon_0]$, except for a set of $\epsilon$ of measure exponentially small with $\epsilon_0$. In case that $\epsilon$ is fixed (and sufficiently small), we prove the existence of invariant tori for every vector of frequencies close to the one of the initial torus, except for a set of frequencies of measure exponentially small with the distance to the unperturbed torus. As a particular case, if the perturbation is autonomous, these results also give the same kind of estimates on the measure of destroyed tori. Finally, these results are applied to some problems of celestial mechanics, in order to help in the description of the phase space of some concrete models.