2017-02-07 3 views
1

나는 첫 번째 VBA 서브를 썼고, 그 방법을 잘 알고 있지만 틀린 부분을 알아 내지 못합니다. 더블 바이트 일본어와 라틴 문자와 스페이스의 문자열이있는 경우 더블 바이트 공백, 문자, 숫자 및 구두점을 선택적으로 싱글 바이트로 변환해야합니다. 더블 바이트에서 싱글 바이크 문자로의 VBA 선택적 변환

In this picture, the top row represents the input and the bottom row the desired output of spaces, letters, numbers, and punctuation converted to single-byte while the Japanese characters remain intact.

However, this is what is happening when I run the sub. Clearly it's working, but also something is off with my concatenation.

코드는 "잡기 및 변환"문제가 전각 문자에 해당 UTF-16 코드의 범위에 다음과 작품을 기반으로

. 지역화 된 컴퓨터에서만 작동합니다 (예 : 언어/지역이 일본으로 설정된 경우).하지만 내 코드의 문제가 현지화 된 기능과 관련이 있다고 생각하지 않습니다. 내가 뭘 잘못했는지에 대한 도움은 크게, 크게 감사하겠습니다!

Public Sub Converter() 
    Dim objRange As Range 
     For Each objRange In ActiveSheet.UsedRange 
     Call Alphanumeric(objRange) 
    Next 
End Sub 

Private Sub Alphanumeric(ByRef objRange As Range) 
    Dim strIn As String 
    Dim strOut As String 
    Dim strAlphanumeric As String 
    Dim i As Integer 

    If objRange.HasFormula Or _ 
     VarType(objRange.Value) <> vbString Then 
     Exit Sub 
    End If 

    strIn = objRange.Value 
    strOut = "" 
    strAlphanumeric = "" 

    For i = 1 To Len(strIn) 
     If AscW(Mid(strIn, i, 2)) + 65536 >= 65280 And _ 
      AscW(Mid(strIn, i, 2)) + 65536 <= 65370 Then 
      strAlphanumeric = strAlphanumeric & Mid(strIn, i, 1) 
     Else 
      If strAlphanumeric <> "" Then 
       strOut = strOut & StrConv(strIn, vbNarrow) 
       strAlphanumeric = "" 
      End If 
      strOut = strOut & Mid(strIn, i, 1) 
     End If 
    Next 

    objRange.Value = strOut 

End Sub 

답변

0

나는 내 눈

strOut = strOut & StrConv(strAlphanumeric, vbNarrow) 
+1

예에이어야한다 라인을

strOut = strOut & StrConv(strIn, vbNarrow)을 의심! 그랬어. 정말 고맙습니다. – mixadelic