Consulting

Results 1 to 4 of 4

Thread: VBA unknown character - error

  1. #1

    VBA unknown character - error

    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.


    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.


    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

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    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


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3

    Thumbs up

    Ah! Actually it's chr(9),
    Chr(9) HT Horizontal Tab
    https://testguild.com/qtp-ascii-chr-code-chart/

    Fixed now. Thanks Paul_Hossler

    Quote Originally Posted by Paul_Hossler View Post
    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

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Good

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

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •