Weird runtime issue

Hi all, I’m having a very, very weird issue with a script, where it’s deciding that a hardcoded string is sometimes null.

I say sometimes, because it seems to only run if a very specific set of things is true:

  1. both outlook and excel are running prior to script launch.
  2. I run the script in the ISE first after making some minor change (Usually commenting or uncommenting line 118) and saving the file. I don't change any of the code logic. Just that one "write-host" line gets (un)commented out.
  3. Then it will run for a while before it decides that $theBodyText is actually a null value. which it is not, it's hardcoded as a string.
The script is here:

(it’s way too big to paste in here.)

I’m really confused as to what’s going on with it.