1

I have an excel file which work well with Excel 2007, now my company upgrade all PC to Windows 10 Enterprise v1809 and Office 2016, then it got error runtime error 5.

Here is my code, the error throw from StrConv line,

Tried Google but no help, is there anyway may help me fix this problem?


Update 1:

I'm working with many Japanese documents so I've changed my system locale to Japanese (in Control Panel/Region/Administrative/System Locale)

Update 2:

I don't want to convert Kanji (Chinese characters in my source), I want to convert double-byte English characters (1F-2F) to single-byte English character (1F-2F)

Public Sub 階段問合せ書作成()

Dim Kaidan1 As Worksheet
Dim N_ws As Workbook
Dim WB As Workbook

    Set WB = ActiveWorkbook


    jigyousyo = Range("事業所")
    kaidan_name1 = StrConv(Range("階数①").Value, vbNarrow)
    kaidan_name2 = StrConv(Range("ŠK”‡A").Value, vbNarrow)

debug info

strconv runtime error 5

my system locale is Japanese

Luke
  • 1,623
  • 3
  • 24
  • 32
  • 1
    On the [Microsoft documentation-page for `StrConv`](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/strconv-function), it says the constant `vbNarrow` _"cause a run-time error when used in locales where it does not apply."_ Could that be the case here? – eirikdaude Aug 25 '20 at 07:38
  • What's the result you expect from StrConv in this case? The Chinese characters of your original string are 2-byte characters by nature. How could they be converted to 1-byte characters? – Variatus Aug 25 '20 at 07:56
  • @eirikdaude : I've checked that point so I've already changed my System Locale to Japanese. – Luke Aug 25 '20 at 08:35
  • @Variatus : I've updated my question, the string which I want to convert is not those Chinese characters, they are double-byte english characters `1F-2F` – Luke Aug 25 '20 at 08:36
  • 1
    Sorry. Actually, that was quite clear. I was confused. Would you need help with a loop to test which of the characters don't translate to single byte? – Variatus Aug 25 '20 at 08:59

2 Answers2

3

The syntax of the function is

StrConv(string, conversion, [ LCID ])

Instead of

StrConv(Range("階数①").Value, vbNarrow)

You may use this instead.

StrConv(Range("階数①").Value, vbNarrow, 1041)

1041 is Locale ID of Japan. No matter what the system locale and Format in your PC is set to, it should work.

chucta
  • 31
  • 4
  • Passing the Locale ID 1041 worked for me. I'm in America processing Excel files from Japan. – Ben Jul 07 '22 at 23:56
1

You have to change System Locale and Format in Region to Japanese

D T
  • 3,522
  • 7
  • 45
  • 89