Carl Gustaf af Leopold, Poet, State Secretary