Duke of York spoke highly of Spencer's conduct (London Gazette, 24 Sept. 1799). The attack on the French positions was renewed on 2 Oct., but Pulteney's division was not actively engaged.
The British forces returned to England in November. At the end of March 1800 the 40th embarked for the Mediterranean, Spencer being in command of the 2nd battalion. After some months in Minorca, and after the abandonment of the attempt upon Cadiz, it went to Malta; and the four flank companies, under Spencer, accompanied Abercromby's expedition to Egypt. They formed part of the reserve under Moore, and in the landing at Aboukir Bay, on 8 March 1801, they were among the first troops ashore. There was a sandhill in their front, from which the fire was very severe. ‘With Moore and Spencer at their head, the 23rd and 28th regiments, and the four flank companies of the 40th, breasted the steep sandhill. Without firing a shot they rushed at one burst to the summit of the ridge, driving headlong before them two battalions of the enemy, and capturing four pieces of field artillery’ (Bunbury, p. 95; cf. Smythies, p. 86, from Landmann's Recollections). His coolness and conduct were mentioned in the highest terms by Moore and Abercromby (London Gazette, 9 May 1801).
Spencer and his men were in the hottest part of the battle of Alexandria (21 March), and helped to disperse the cavalry who were pressing on the 42nd. On 2 April he was sent to Rosetta with one thousand British infantry, accompanied by four thousand Turks. The French evacuated it on his approach, and on the 19th he took Fort St. Julien, which commanded the western branch of the Nile. Hutchinson, in his despatch, spoke of the zeal, activity, and military talents which he had displayed (ib. 5 June). On 17 Aug., shortly before the fall of Alexandria, Spencer was in command of a detachment of the 30th, less than two hundred strong, which held an advanced post, known as ‘the Green hill,’ on the east side of the city. The French made a sortie with six hundred men to cut off this detachment; but by Spencer's order it charged them with the bayonet, and drove them back into the place (ib. 22 Oct.).
After his return to England, Spencer served on the staff in Sussex, first as brigadier-general, and from 1 Jan. 1805 as major-general. George III, with whom he was a great favourite, made him one of his equerries, and he spent much of his time at court. In July 1807 he was appointed to the command of a brigade in the expedition to Copenhagen. The expedition returned in October, and shortly afterwards he was sent to the Mediterranean with about five thousand men with secret instructions. ‘He was to co-operate with Moore against the Russian fleet in the Tagus; he was to take the French fleet at Cadiz; he was to assault Ceuta; he was to make an attempt upon the Spanish fleet at Port Mahon’ (Napier, bk. ii. ch. iii.). Delayed by bad weather, which dispersed his force, he did not reach Gibraltar till March 1808. He went on to Port Mahon, but, on the outbreak of the Spanish insurrection, returned to Cadiz. Spain and England were nominally at war, and the Spaniards refused to let British troops enter Cadiz. Spencer would not risk his small force by advancing inland; but his appearance off the mouth of the Guadiana encouraged the insurgents in the south of Portugal, and prevented the detachment of troops from Junot's army to aid Dupont in his attempt on Seville.
The surrender of Dupont at Baylen on 19 July made it needless for Spencer to remain longer near Cadiz, and on 5 Aug. he joined Wellesley's force at the mouth of the Mondego, anticipating an order which Wellesley had sent him to that effect. He was present as second in command at the actions of Roliça and Vimiera. Wellesley acknowledged his assistance in his despatches, and recommended him for some mark of the king's favour. ‘There never was a braver officer, or one who deserved it better’ (Desp. vi. 124). It was deferred on account of the inquiry into the convention of Cintra, but on 26 April 1809 he was made K.B. He also received the gold medal.
He returned to England in October 1808, as his health would not let him share in Moore's campaign in Spain. He was one of the witnesses at the inquiry into the convention. His evidence was in its favour; but he supported Wellesley's contention that more might have been made of the victory of Vimiera. He had been made colonel of the 9th garrison battalion on 25 Nov. 1806, and transferred to the 2nd West India regiment on 25 June 1808; and on 31 Aug. 1809 he was made colonel-commandant of the 2nd battalion of the 95th (now rifle brigade).
In May 1810 he went back to the Peninsula to succeed Sir John Coape Sherbrooke [q. v.] as second in command under Wellington, but on the understanding that Graham, who was then at Cadiz, would fill that post if summoned to the army, and would be Wellington's successor in case of need. Spencer was given the command of the first division