PDA

View Full Version : [SOLVED:] VBA unknown character - error



Lacisnesnon
09-13-2020, 05:46 PM
Hi all,

I have emails with subjects from a specific authority that includes a special character. It shows up as a couple of spaces or a tab in the email subject in Outlook, however, when manually file saving the target email Outlook has already removed this character from the subject.
https://www.mrexcel.com/board/attachments/email_subject-png.22299/

I have a file saver macro module that processes a selected email and saves it to a predetermined location, however, when it extracts the subject from the email it includes this special character which shows up in the error message as a SQUARE (not [] as there are no pixel spaces between the two brackets). See attached images for examples.
https://www.mrexcel.com/board/attachments/email_subject_vba_save-png.22300/

I have tried processing all special characters that I am able to with no resolution. "#$%()^*&/\:;*?<>+[]." The error still persists.

I guess the only other way is to write code that will process each character in a string until there is an error which then records the error character number in the string and replaces it with something valid. I don't want to have to do this for all emails.

Any ideas would be appreciated.
Thanks in advance

Paul_Hossler
09-13-2020, 06:16 PM
When you get to that point, go to the Immediate Window and enter

?Asc(Mid(sName,28,1))

to see what the char is, and replace it with a space or something


This is what I got with * as the mystery character and the literal value for sName , but use sName instead



?asc(mid("20200907-115609-AYCA-6UJ77L*Woolworths",28,1))
42

?replace("20200907-115609-AYCA-6UJ77L*Woolworths",chr(42), " ")
20200907-115609-AYCA-6UJ77L Woolworths



Bit prettier



Option Explicit


Sub Frag()


Dim sName As String


sName = "20200907-115609-AYCA-6UJ77L*Woolworths"


MsgBox Asc(Mid(sName, 28, 1))


sName = Replace(sName, Chr(42), " ")


MsgBox sName


End Sub

Lacisnesnon
09-13-2020, 06:38 PM
Ah! Actually it's chr(9),

Chr(9)
HT
Horizontal Tab


https://testguild.com/qtp-ascii-chr-code-chart/

Fixed now. Thanks Paul_Hossler


When you get to that point, go to the Immediate Window and enter

?Asc(Mid(sName,28,1))

to see what the char is, and replace it with a space or something


This is what I got with * as the mystery character and the literal value for sName , but use sName instead



?asc(mid("20200907-115609-AYCA-6UJ77L*Woolworths",28,1))
42

?replace("20200907-115609-AYCA-6UJ77L*Woolworths",chr(42), " ")
20200907-115609-AYCA-6UJ77L Woolworths



Bit prettier



Option Explicit


Sub Frag()


Dim sName As String


sName = "20200907-115609-AYCA-6UJ77L*Woolworths"


MsgBox Asc(Mid(sName, 28, 1))


sName = Replace(sName, Chr(42), " ")


MsgBox sName


End Sub

Paul_Hossler
09-14-2020, 12:13 PM
Good

You can mark this [SOLVED] - #3 in my sig