This work deals with the problem of controlling the nonlinear dynamics, in general, and the dynamic pull-in, in particular, of an electrically actuated microbeam. A single-well softening model recently proposed by Gottlieb and Champneys [1] is considered, and a control method previously proposed by the authors is applied. Homoclinic bifurcation, which triggers the safe basin erosion eventually leading to pull-in, is considered as the undesired event, and it is shown how appropriate controlling superharmonics added to a reference harmonic excitation succeed in shifting it towards higher excitation amplitudes. An optimization problem is formulated, and the optimal excitation shape is obtained. Extensive numerical simulations aimed at checking the effectiveness of the control method in shifting the erosion of the safe basin are reported. They highlight good performances of the control method beyond theoretical expectations.