어떻게 확인할 수 있습니하는 경우 텍스트는 키릴 문자가 있습니까?
-
03-07-2019 - |
문제
내 정크 메일 폴더를 채우는 메시지로 구성되어에서 나타나는 것이 이 키릴 문자 알파벳이 있습니다.는 경우 메시지 본문 또는 메시지를 주제에 키릴 문자,나를 영구적으로 삭제하려습니다.
내 화면에 나오는 키릴 문자,그 때 반복하는 메시지를 통해서 VBA 내 전망,"주"속성의 메시지 질문을 반환합니다.
어떻게 확인할 수 있습니다면 메시지의 제목에 키릴 문자가 있습니까?
(주의:내가 조사했"InternetCodepage"속성-그것은 일반적으로 서유럽.)
해결책
이 String
데이터 VB/VBA 처리할 수 있는 유니코드 문자,그러나 IDE 자체가 문제들을 표시하기(따라서 질문을 표시).
내가 쓴 IsCyrillic
기능할 수 있도록 도와줄 수 있는니다.이 함수는 단일 String
인수 및 반품 True
문자열이 있는 경우에는 적어도 하나의 키릴 문자입니다.이 코드 Outlook2007 및 작동하는 것 같다.을 테스트하고 몇 가지 이메일 키릴 문자와 텍스트에서는 제목하고 검증하는 테스트 코드는 올바르게 선택 사람들의 e-메일 중에 다른 모든니다.
그래서 저는 실제로 두 개의 코드:
- 가 포함된 코드
IsCyrillic
기능입니다.이 수 있는 복사하여 붙여 넣은 새로운 VBA 모듈 또는 추가 코드가 이미 있습니다. - 이
Test
일상적인 내가 쓴(에 Outlook VBA)을 테스트하는 코드를 실제로 작동합니다.그것은 사용하는 방법을 보여줍IsCyrillic
기능입니다.
코드
Option Explicit
Public Const errInvalidArgument = 5
' Returns True if sText contains at least one Cyrillic character'
' NOTE: Assumes UTF-16 encoding'
Public Function IsCyrillic(ByVal sText As String) As Boolean
Dim i As Long
' Loop through each char. If we hit a Cryrillic char, return True.'
For i = 1 To Len(sText)
If IsCharCyrillic(Mid(sText, i, 1)) Then
IsCyrillic = True
Exit Function
End If
Next
End Function
' Returns True if the given character is part of the Cyrillic alphabet'
' NOTE: Assumes UTF-16 encoding'
Private Function IsCharCyrillic(ByVal sChar As String) As Boolean
' According to the first few Google pages I found, '
' Cyrillic is stored at U+400-U+52f '
Const CYRILLIC_START As Integer = &H400
Const CYRILLIC_END As Integer = &H52F
' A (valid) single Unicode char will be two bytes long'
If LenB(sChar) <> 2 Then
Err.Raise errInvalidArgument, _
"IsCharCyrillic", _
"sChar must be a single Unicode character"
End If
' Get Unicode value of character'
Dim nCharCode As Integer
nCharCode = AscW(sChar)
' Is char code in the range of the Cyrillic characters?'
If (nCharCode >= CYRILLIC_START And nCharCode <= CYRILLIC_END) Then
IsCharCyrillic = True
End If
End Function
를 들어 사용법
' On my box, this code iterates through my Inbox. On your machine,'
' you may have to switch to your Inbox in Outlook before running this code.'
' I placed this code in `ThisOutlookSession` in the VBA editor. I called'
' it in the Immediate window by typing `ThisOutlookSession.TestIsCyrillic`'
Public Sub TestIsCyrillic()
Dim oItem As Object
Dim oMailItem As MailItem
For Each oItem In ThisOutlookSession.ActiveExplorer.CurrentFolder.Items
If TypeOf oItem Is MailItem Then
Set oMailItem = oItem
If IsCyrillic(oMailItem.Subject) Then
' I just printed out the offending subject line '
' (it will display as ? marks, but I just '
' wanted to see it output something) '
' In your case, you could change this line to: '
' '
' oMailItem.Delete '
' '
' to actually delete the message '
Debug.Print oMailItem.Subject
End If
End If
Next
End Sub
다른 팁
메시지의 "주제"속성은 많은 물음표를 반환합니다.
고전적인 문자열 인코딩 문제. 해당 속성이 ASCII를 반환하는 것처럼 들리지만 UTF-8 또는 유니 코드를 원합니다.
당신은 이미 쉬운 솔루션을 가지고있는 것 같습니다.
제휴하지 않습니다 StackOverflow