Summary
This macro code works, and it also inserts the original slide number in the top left corner of each slide: https://gist.github.com/pcmoritz/4b0e1be7f2dfcc4e51e2ace50426f67d
Details
This is a method that worked in April 2025 with the Microsoft 365 (subscription) version of Powerpoint. I figured it out by following the links in this comment. This answer includes how to keep the original slide-numbers.
For full information, start by reading these two pages by Neil Mitchell:
https://web.archive.org/web/20231004191351/https://neilmitchell.blogspot.com/2007/11/creating-pdf-from-powerpoint-with.html
https://web.archive.org/web/20231004194728/https://neilmitchell.blogspot.com/2007/11/powerpoint-pdf-part-2.html
At the bottom of the second page are some comments where people point out a problem with Neil Mitchell's macro if each slide shows a slide-number. Each new slide has a new number, so if slide 10 in the original has two animations then it might become slides 10 to 12 in the new version. Then there is a comment by Philipp Moritz:
Here is how you can use this code and retain the slide numbers from the old presentation:
https://gist.github.com/pcmoritz/4b0e1be7f2dfcc4e51e2ace50426f67d
You need to deactivate the slide numbers, this will insert a text box per slide with the right number from the old slide.
In other words, the code on the github page is based on the code on the neilmitchell page, but it retains the slide numbers from the original presentation, by inserting the original slide-numbers as hard-coded numbers near the top left corner of each slide. As well as running the macro, you also need to delete the conventional slide numbers yourself - these appear on a master slide as <#>.
If you want to change the position, font, etc of the "slide numbers" you would probably need to change something in these lines in the macro:
Set oshp = .AddTextbox(msoTextOrientationHorizontal, 10, 10, 100, 50)
oshp.TextFrame.TextRange.Font.Name = "Arial"
oshp.TextFrame.TextRange.Font.Size = 12
oshp.TextFrame.TextRange.InsertAfter "" & i