下のコードは文字列を生の文字コードに(マクロ暗号化)、生の文字コードを文字列に変換するコード(マクロ復号化)です。生の文字コードでは
ダメだというならば前回、書いたとおり「0~9、A~F」を適当な文字に
置換するコードを「マクロ暗号化」の最後に付け加えるという手もあります。
(その時には、マクロ「復号化」の頭にもとの文字に戻す処理を
加えて下さい)
'------------------------------------------------------------
Sub 暗号化()
Dim CharaCnt As Long
Dim i As Long
Dim MyExit As Integer
Dim NetCharaNum As Long
CharaCnt = Selection.Characters.Count
For i = 1 To CharaCnt
If (AscW(Mid(Selection.Text, i, 1)) > 30) Or (AscW(Mid(Selection.Text, i, 1)) < 0) Then NetCharaNum = NetCharaNum + 1
Next
For i = 1 To NetCharaNum
Selection.Collapse
Selection.MoveRight wdCharacter, 1, True
Selection.ToggleCharacterCode
Selection.Collapse wdCollapseEnd
Do While Selection.Text = Chr(9) Or Selection.Text = Chr(11) Or Selection.Text = Chr(13)
Selection.MoveRight wdCharacter, 1
MyExit = MyExit + 1
If MyExit > 20 Then Exit Sub
Loop
MyExit = 0
Next
End Sub
'------------------------------------------------------------
Sub 復号化()
Dim CharaCnt As Long
Dim i As Long
Dim MyExit As Integer
Dim NetCharaNum As Long
CharaCnt = Selection.Characters.Count
For i = 1 To CharaCnt
If AscW(Mid(Selection.Text, i, 1)) > 30 Then NetCharaNum = NetCharaNum + 1
Next
For i = 1 To NetCharaNum \ 4
Selection.Collapse
Selection.MoveRight wdCharacter, 4, True
Selection.ToggleCharacterCode
Selection.Collapse wdCollapseEnd
Do While Selection.Text = Chr(9) Or Selection.Text = Chr(11) Or Selection.Text = Chr(13)
Selection.MoveRight wdCharacter, 1
MyExit = MyExit + 1
If MyExit > 20 Then Exit Sub
Loop
MyExit = 0
Next
End Sub
最近のコメント