We propose a model for the excitation of horizontally polarised transverse (kink) magnetoacoustic oscillations of solar coronal loops by upflows associated with coronal mass ejections. If the magnetic field in the plasma that is dragged in the vertical direction by the flow is parallel to the loop, the phenomenon of vortex shedding causes the appearance of a quasi-periodic horizontal force that is applied to alternating sides of the loop. The period of the force is determined by the flow speed and the loop's minor radius. The oscillations are excited the most effectively when the force is in resonance with the natural frequency of the kink oscillations. This model can explain the selectivity of the excitation of the oscillations and the initial growth of the oscillation amplitude.