通过更改字符ASCII来屏蔽Excelmacros数据
我正在通过添加字符的ASCII来处理数据遮罩工具,但是一旦达到最大的ASCII码,它将会出现错误。
如果已经达到最大ASCII码,有什么办法可以防止或者忽略添加的ASCII码?
我的Excel代码
Sub DataMask() Dim rngCell As Range Dim intChar As Integer Dim strCheckString As String Dim strCheckChar As String Dim intCheckChar As Integer Dim strClean As String For Each rngCell In Selection strCheckString = rngCell.Value strClean = "" intChar = 1 If strCheckString <> "" Then For intChar = 1 To Len(strCheckString) strCheckChar = Mid(strCheckString, intChar, 1) intCheckChar = Asc(strCheckChar) + 68 strClean = strClean & Chr(intCheckChar) Next intChar rngCell.Value = strClean End If Next rngCell End Sub
你可以包含这样一段代码:
If intCheckChar <= 255 Then newCheckChar = Chr(intCheckChar) Else newCheckChar = strCheckChar End If strClean = strClean & newCheckChar
取代
strClean = strClean & Chr(intCheckChar)
所以如果新字符的代码超过了255,它只是使用旧字符。
这是整个子几个debugging语句:
sub DataMask() Dim rngCell As Range Dim intChar As Integer Dim strCheckString As String Dim strCheckChar As String Dim intCheckChar As Integer Dim strClean As String Dim newCheckChar As String For Each rngCell In Selection strCheckString = rngCell.Value strClean = "" intChar = 1 If strCheckString <> "" Then For intChar = 1 To Len(strCheckString) strCheckChar = Mid(strCheckString, intChar, 1) intCheckChar = Asc(strCheckChar) + 68 ' New code If intCheckChar <= 255 Then newCheckChar = Chr(intCheckChar) Else newCheckChar = strCheckChar End If strClean = strClean & newCheckChar Debug.Print ("intChar=" & intChar) Debug.Print ("intCheckChar=" & intCheckChar) ' end of code Next intChar rngCell.Value = strClean End If Next rngCell End Sub