Like most economists, I like to present my research using Beamer. This is in part for costly signaling reasons – doing my slides via TeX proves that I am smart/diligent enough to do that. But it’s also for stylistic reasons: Beamer can automatically put a little index at the top of my slides so people know where I am going, and I like the default fonts and colors.
Moreover, Beamer forces me to obey the First Law of Slidemaking: get all those extra words off your slides. Powerpoint will happily rescale things and let you put tons of text on the screen at once. Beamer – unless you mess with it heavily – simply won’t, and so forces you to make short, parsimonious bullet points (and limit how many you use).
Not everyone is on the same page about which tool to use all the time, which in the past has occasionally meant I needed to take my coauthor’s Powerpoint slides and copy them into Beamer line-by-line. Fortunately, today I found a solution for automating that process.
StackExchange user Louis has a post where he shares VBA code that can quickly move your Powerpoint slides over to Beamer. His code is great but I wasn’t totally happy with the output so I made a couple of tweaks to simplify it a bit. You can view and download my code here; I provide it for free with no warranties, guarantees, or promises. Use at your own risk.
Here is how to use it:
- Convert your slides to .ppt format using “Save As”. (The code won’t work on .pptx files).
- Put the file in its own folder that contains nothing else. WARNING: If files with the same names as those used by the code are in this folder they will be overwritten.
- Download the VBA code here (use at your own risk).
- Open up the Macros menu in Powerpoint (You can add it via “Customize the Ribbon”. Hit “New Group” on the right and rename it “Macros”, then select “Macros” on the left and hit “Add”.)
- Type “ConvertToBeamer” under “Macro name”, then hit “Create”
- Select all the text in the window that appears and delete it. Paste the VBA code in.
- Save, then close the Microsoft Visual Basic for Applications window.
- Hit the Macros button again, select “ConvertToBeamer” and run it.
- There will now be a .txt file with the Beamer code for your slides in it. (It won’t compile without an appropriate header.) If your file is called “MySlides.ppt” the text file will be “MySlides.txt”
- You need to manually fix a few special characters, as always when importing text into TeX. Look out for $, %, carriage returns, and all types of quotation marks and apostrophes. I also found that some tables came through fine while others needed manual tweaking.
One issue I had with the output was that it didn’t have any indentations, making it hard to recognize nested bullets. Fortunately I found this page that will indent TeX code automatically.
I found this to be a huge time saver. Even with figuring it out for the first time, tweaking the code, and writing this post, it still probably saved me several hours of work. Hopefully others find this useful as well.
Works great, it saves a lot of time indeed! Thanks for sharing!
John
It’s in point of fact a great and helpful piece of information. I am happy that you shared this helpful info with us.
Please stay us up to date like this. Thanks for
sharing.
It is great, thanks a lot for sharing this information.
Thanks a lot Jason for sharing this info! However, I tried to follow the steps but got stuck at stage 8. When I run it, it came with the error message “Run-time error ’52’: Bad file name or number”. The Debug points to this line: Set objTextFile = objFileSystem.CreateTextFile(Dest, True, True). Could you please help? Thanks!
I just tried this in PowerPoint 2016 and it runs with no problems. What version of PowerPoint are you using?
Some ideas:
– Did you delete everything in the macro box before pasting in the code?
– Are you using a macro-enabled powerpoint file? It’s got to be .ppt or .pptm or it won’t run.
Many thanks for your quick reply Jason! Yes, I did save it as .ppt (powerpoint 1997-2003). I also deleted the code in the macro box before pasting in your code. It may have to do with the way I created the macro menu. I am also new to Beamer. Thanks!
Hi
Jason, firstly thanks for the script. This is way past the date that will help Sina, but for others reading this post the key to resolving these issues is to use the debugger. I hit a similar issue and found that the Pth variable started with “https:://” as I had created the base presentation on my OneDrive account. Moving the presentation to a local folder resulted in success.
Hi
I am getting this error message.
” Set objTextFile = objFileSystem.CreateTextFile(Dest, True, True)
objTextFile.WriteLine “\section{” & Name & “}”
With Application.ActivePresentation.PageSetup
wdth = .SlideWidth
hght = .SlideHeight
End With”
Please help me how to solve this.
“Run-time error ’52’: Bad file name or number”. The Debug points to this line: Set objTextFile = objFileSystem.CreateTextFile(Dest, True, True).
I am not the original author of the code, so I can’t help with specific error messages. Anecdotal experience suggests that some installations of PowerPoint do not work well with this – have you tried it on another machine?
If that doesn’t work, you could try contacting the original author over on StackExchange.
Thanks I tried it on other machine it worked .
thanks i tried it on another laptop it worked. thanks
Thanks very much Jason for putting this together, it’s an invaluable contribution. A couple of comments about my experience, which since nobody else has mentioned them, may be ideosyncratic.
1) I needed to have the Developer box checked in the right column of
File -> Options -> Customize Ribbon
Else I couldn’t see the Developer-> Macros tab, and therefore couldn’t proceed.
3) Jason says to cut and paste the contents of ConvertToBeamer into the Visual Basic window . For some reason Paste was greyed out for me when I tried to do this. But I could input the contents using Insert -> File.
4) Once the file was created and converted inserted into a beamer template I got lots of latex compilation errors relating to Unicode characters not being supported by latex. Eventually I gave up on trying to find out what these characters represented, and simply used commands of the following form in the latex preamble, for each unidentified unicode character:\DeclareUnicodeCharacter{XX}{}, where XX is the Unicode character that threw the error.
I’m getting “run-time error ‘429’: ActiveX component can’t create object”. Runninc this on a Mac — ActiveX is probably windows-only.
I get the same error 429.
I don’t have a Mac (and didn’t write this script) – have you tried it on a Windows machine?
I did and on a Windows machine works perfectly! Thanks, Jason!
Thanks for sharing your great work Jason! A big time saver!
I haven’t tried it myself for this purpose, nut you could try pandoc.
I haven’t tried it myself for this purpose, but you could try pandoc
It seems pandoc only converts TO ppt/pptx, and not FROM.
Great article.
COOL
It works great, thanks a lot.
Thanks for sharing, I can’t wait to try it