I am writing a macro for Microsoft Outlook, and I am having an issue when the code is stripping out illegal characters from the subject of a message. The code below works as expected no matter what type of string I input, but the issue arises with one of the e-mails; it has a character in the subject line that shows up as a small box. I am pretty sure this means the character is not recognized in ASCII, but what is more interesting is when it is passed into the VBA code it shows up as a question mark when I hover over the variable. So far I cannot find a way to remove this character, and the resulting string is passed on to create a directory, crashing the macro.
Sub FigureThisOut() 'same as: !, ", #, *, ., /, :, <, >, ?, \, | invalidChars = Array(Chr(33), Chr(34), Chr(35), Chr(42), Chr(46), Chr(47), Chr(58), Chr(60), Chr(62), Chr(63), Chr(92), Chr(124)) msgSubject = "Testing! The\" & "Subject# With* All. Of/ The: Restricted< Characters> Here? Goes\ Nothing|" MsgBox (msgSubject) For j = LBound(invalidChars) To UBound(invalidChars) temp = Replace(msgSubject, invalidChars(j), " ") msgSubject = temp Next j msgSubject = Replace(msgSubject, "RE ", "") msgSubject = Replace(msgSubject, "FW ", "") msgSubject = Trim(msgSubject) MsgBox (msgSubject) End SubI also cannot find a way to recreate the issue without running the whole macro and extracting the specific subject of the e-mail, which in this case I cannot share publicly (go figure!). Hopefully I am just missing something simple, but any advice would be appreciated!
Thank you for your time,
whoabuddy


Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Back to top










