Three Times the Internet has Helped Me with My Coding

Every coder of every level of expertise has to turn to the documentation at one point or another. Whether this is when learning a new language or framework, or when stumped when a certain error message appears. In the past few months, I have had the need to fall back and trust the internet to catch me, and it hasn’t let me down. The more interesting thing is that I found the solution to my problems in three different places.

The Github Hail Mary

A few months ago, I needed a way to compile complex internal information and have it distributed to our customers via email. There really weren’t any easy solutions. We didn’t have the budget to obtain a third-party vendor. The data came from four different sources. We needed to use our email servers and program (Outlook) to distribute the messages. The project was beyond simple mail merging and I knew that trying to code the entire project in VBA would be tedious, and would involve the use of my least favorite program: Microsoft Access. However, I did know that VBA would be required in order to automate the generation of the messages. The question was what was the best way to get the data into Outlook so that VBA could generate the necessary output?

I turned to Github to see what other people had coded. I came across a VBA script called outlook-XMLmassMailer.

As an aside, I highly suggest browsing Github anytime you have a new coding challenge. Doing so can help you see how other people are dealing with similar issues. Additionally, it can also give you a jump start on writing code. Just be careful that you review what you are working with, to make sure that there isn’t any opportunistic code lurking in the files.

In a nutshell, the program takes XML and uses it to generate emails based on the markup. Now all I had to do was write a quick Python script that merged the data to my needs and which generated some XML output. I would then load the XML into the macro and my emails would be created in a fraction of the time otherwise required to do the work manually.

The only problem was that I couldn’t get the form to load when running the macro! Specifically, I was receiving the “Invalid Outside Procedure” error upon loading. I spent the entire next day searching on the error and trying everything but to no avail. Finally, I reached out to the developer, a complete stranger and told him or her it wasn’t working. Within 24 hours, the developer resolved the issue, despite the fact that they were under no obligation to do so. My company uses the macro to this day and may expand its use in the future.

Open Source Slide Show

For one of my volunteer projects, I was asked to develop a way to display an online ad journal. The organization was collecting the information for the form in a way that included the HTML markup for the ads.  At a basic level, creating a slide show that draws from the form data submitted online would meet the requirements. Again I turned to Github, but this time didn’t find anything that perfectly met my needs, and I turned to a general Google search. It turns out that slideshows/sliders are pretty common, and a lot of open source projects exist around it. I settled on one developed by I’ll write a post about how it comes out in a few weeks after the project is complete.

Problems with Packaging

In the past few months I have been working hard to make sure that the scripts that I write are more accessible. What I mean by this is that I shouldn’t be the only person who knows how to run the processes that the rest of my company relies on each month. However, I am the only one on my team who has Python natively installed on their machine. So, for others to be able to run my programs, the programs need to be packaged into an executable format. This is easy enough to do, but the additional Python packages I use caused me some trouble.

Specifically, I use the openpyxl package to help me manipulate Excel spreadsheets. Programming Excel in this is way faster than any human could possibly copy and paste, and helps reduce the possibility of error.  For these two reasons, and the small fact that I am better at programming in Python than VBA, I much prefer to program Excel using Python than writing macros. Anyway, my company likes its logo inserted at the top of reports, and openpyxl has a method that will do this for you. The problem is that bbfreeze was not importing the PIL package that openpyxl relies on to do this. Multiple hours of internet searching did not turn up an answer. Finally, I did what I am always afraid to do, and that is post a question on StackOverflow. I’ll explain in a future blog post my anxieties around posting on StackOverflow.

Anyway, my approach when I finally do get up the courage to post on StackOverflow is to disseminate my question across several channels. I email my developer friend, and I post it on Facebook. This time I also posted it in a specific Facebook group which I knew had a lot of developers. In this last group, one participant had the idea to write a small program which used the PIL package and tr to make that into an exe and see what happened. It also didn’t work, but with is method, I was able to iterate over which packages it was missing until I knew all the dependencies for PIL. With thik knowledge in hand, I included the missing dependencies and the original program executed flawlessly.