Automate Boring Office Tasks with ChatGPT and Python
Introduction
In my previous discussions, I covered how to use ChatGPT and Python to automate Excel tasks. This time, I’m taking it further by showcasing how ChatGPT can assist in automating Outlook, creating PowerPoint presentations, generating interactive charts, merging PDFs, composing emails, and even building an entire website. The results are truly impressive, and I believe that after going through this post, you’ll be able to automate some of the tedious office tasks you might have.
1. Example: Distribute Excel files with Outlook
Let’s start with sending Excel files to different recipients using Outlook. I have prepared an overview in the financial_data.xlsx workbook. This workbook contains data for various countries. My goal is to have ChatGPT create a Python script that reads data from the email list sheet in the workbook. The script should use columns A, B, C, and D to compose Outlook emails with different attachments and recipients.
The code should locate the attachments in a folder called attachments, construct the file path, and include the recipient’s name from column B in the email text along with CC email addresses from columns C and D. I prompted ChatGPT with this request, and despite receiving a warning about content policy violations, it generated the necessary code.
After pasting the code into a Python file and executing it, Outlook created emails for each country with the correct email addresses, CCs, attachments, and text. I noticed a depreciation warning, which I brought to ChatGPT’s attention. It quickly provided a modified version of the code, eliminating the warning. Now, the emails are created but not sent out, which is exactly what I wanted. In the future, if I need to send them directly, ChatGPT even explained how to modify the code for that.
2. Example: Automate PowerPoint
Next, I wanted to create a complete PowerPoint presentation from scratch. Using the same Excel files, I plan to group the sales data by product and create a bar chart. The Python script should access an input folder, read all files, exclude any missing values, and group the sales accordingly.
In my prompt, I specified the use of the Seaborn library for chart creation. It’s crucial to be specific about the library you want to use; otherwise, ChatGPT may choose a different one, such as Matplotlib. The charts should be saved in a folder named charts, and the presentation should include a slide for each chart with a title.
After executing the code generated by ChatGPT, I received a future warning, but the code ran successfully. I now have a new charts folder containing images for each Excel file with aggregated sales by product. The PowerPoint presentation is also saved in the input folder. While it may not look perfect, it’s a great starting point for further customization.
3. Example: Create an interactive chart from Excel data
Instead of static images, I wanted to create an interactive chart using the same data. This time, I asked ChatGPT to sum the sales for each country and plot it in an interactive format. I also included specific color codes in my prompt.
ChatGPT generated a Python script that successfully created an HTML file containing the interactive chart. This allows for a more dynamic representation of the sales data.
4. Example: Merge PDFs
A subscriber reached out to me with a task involving two folders: cover and draft. The cover folder contains PDFs labeled with numbers, which serve as covers for the corresponding PDFs in the draft folder. The goal was to combine these files into a single document, placing the cover first, followed by the appropriate PDF.
After providing ChatGPT with a detailed example of how the files should be matched, it generated a solution. I copied the code into my text editor, but initially received an error message. However, after pasting the error back into ChatGPT, it provided an adjusted version that ran successfully. Now, I have a new output folder containing the merged PDF files, making this process a significant time saver.
5. Example: Write Emails
With the automation of various tasks, I also explored how ChatGPT can assist in writing emails. For instance, I requested it to draft an email to my manager requesting a salary increase. ChatGPT crafted a well-written email that included reasons why the automated solutions I’ve implemented are beneficial to the company.
6. Example: Create a Streamlit website
Lastly, I built an entire website using ChatGPT. The website hosts all the prompts I used throughout this post, providing a centralized resource for others to access the respective chat history.
Outro
These examples illustrate the incredible potential of automating tedious office tasks with ChatGPT and Python. From sending emails to generating presentations and merging documents, the possibilities are endless. I encourage you to explore these tools and see what tasks you can automate in your own workflows.