In this blog post, I will share my experience of leveraging ChatGPT to create a Visual Basic macro that helped me export tables from a PowerPoint slide deck to a Markdown file.
The Challenge
I was in the midst of preparing a slide deck for an Infrastructure as Code Bootcamp scheduled for May. My presentation included numerous tables containing commands and sample code that I wanted to share with the audience and use in my blog posts. I needed a quick and efficient way to export these tables as a Markdown file, but I was unsure of how to achieve this.
Turning to ChatGPT
Given the challenge at hand, I decided to seek help from ChatGPT, a powerful AI language model designed to assist users in various tasks, including programming.
Hey ChatGPT, I need a PowerPoint macro that will find every table in the slide deck and export them to a Markdown file with the Cascadia font as code highlights in Markdown. Can you help me with that?
Of course! Here's a VBA macro that does exactly that:
To use this macro, follow these high-level steps:
Open your PowerPoint presentation.
Press Alt + F11 to open the VBA editor.
Click on Insert in the menu and then click on Module.
Paste the provided VBA code into the newly created module.
Close the VBA editor.
Press Alt + F8 to open the “Macro” dialog.
Select the ExportTablesToMarkdown macro and click “Run”.
Understanding the Code
After receiving the code from ChatGPT, I had a few questions to ensure I understood the functionality and implementation.
Can you explain how the macro checks if the font in the cell is the same as the `TargetFont` (Cascadia Code)?
Sure! The macro uses an `If` statement to compare the font name in the current cell with the `TargetFont` variable, which is set to "Cascadia Code". If the font names match, the cell content is added to the `MarkdownContent` string with code formatting (using backticks). If the font is not the `TargetFont`, the cell content is added without code formatting.
The Outcome
With ChatGPT’s assistance, I successfully created a VBA macro that allowed me to export the tables from my PowerPoint slides to a Markdown file (in this case it is => FilePath = "C:\temp\TablesInMarkdown3.md"). This not only enabled me to share the sample code with my audience but also made it easy to incorporate the code into my blog posts.
The experience of leveraging ChatGPT was incredible, as it helped me overcome a challenge in a time-efficient manner. If you ever find yourself in need of assistance, whether it’s programming or any other task, don’t hesitate to give ChatGPT a try!