A maximum principle is derived for the optimal control of a beam with Kelvin-Voigt damping subject to an external excitation with the control exercised by means of piezoelectric patch actuators. The objective functional is defined as a weighted quadratic functional of the displacement and velocity which is to be minimized at a given terminal time. A penalty term is also part of the objective functional defined as the control voltage used in the control process. The maximum principle makes use of a Hamiltonian defined in terms of an adjoint variable and the control function. The optimal control problem is expressed as a coupled system of partial differential equations in terms of state, adjoint and control variables subject to boundary, initial and terminal conditions. The solution is obtained by expanding the state and adjoint variables in terms of eigenfunctions and determining the optimal control using the maximum principle. Numerical examples are given to demonstrate the applicability and the efficiency of the proposed method.