Special characters (letters čćžšđ) in Excel 2013 VBA code

17,404

Solution 1

As BambiLongGone stated, weird string are not likely to work. I would say your best shot is looking at this article. There 's a tool called Unicode to VBA that you can use to convert all your string in your application. For example :

Čiča gliša

will be converted to

ChrW$(&H10C) & "i" & ChrW$(&H10D) & "a gli" & ChrW$(&H161) & "a"

Solution 2

VBA is ANSI. Ps in it's interactions with Windows. It's UTF16 internaly and COM is also UTF 16. But it's file format is also ANSI so typing wierd strings are not likely to work (because they can't be saved as is).

So character conversion happen automatically with a million rules controlling it (mostly undocumented in an accessible fashion).

If in trouble assign to a byte array. Maybe you bneed toread from unicode file to bypass form's ANSI.

Yourstring() = "blah blah"

VB treats byte arrays as strings if passed to string functions.

Solution 3

Problem is in windows regional settings: Region/Administrative/Language for non-unicode programs, which must be set to language that can handle your special characters.

Solution 4

You can write manually the accents in every piece of code they appear, and you can use the "find & replace" to do it faster. If you have something like:

MsgBox "Código único"

Then you can find and replace:

[ó] to [" & Chr(243) & "]

[ú] to [" & Chr(250) & "]

And so on...

And you will get:

MsgBox "C" & Chr(243) & "digo " & Chr(250) & "nico"

If you don't know the code for each accented letter, then you can use excel with the function "CODE" (Function Char does the opposite)

Also, you could use a list from the internet like this one:

ASCII Code - The extended ASCII table

I just had the same problem and did this procedure. Worked fine using Visual Studio Code and very fast.

Share:
17,404
Jelovac
Author by

Jelovac

Worker at the company for makeing all kinds of paper. I builded my VBA knowlage 'On the go', as work needed solutions for warehouse acounting program. I seek solutions everywhere, primarily here although my questions waren't always wellcome here(banned, on hold, negative votes). Like I wrote them in some kind of Martian language and no one understand them.

Updated on June 05, 2022

Comments

  • Jelovac
    Jelovac almost 2 years

    I made a program in Excel 2010 VBA that contains letters like ć č š...

    Msgbox("Čiča gliša") works.

    Looks like Excel 2013 supports those letters in cells and formulas, but not in VBA.

    VBA replaces them with some symbols which aren't even on the keyboard.

    I get errors executing the code.

    I believe it's something to do with language settings.