需要运行时错误424对象-公钥加密宏

时间:2019-07-09 19:51:29

标签: excel vba encryption

我们目前正在尝试使加密宏在整个工作簿中的多个单元上都可以使用,其中一些单元正在进行很多工作,因此我愿意采取任何措施以改善这种流程。目前,该宏位于我们的“完成表单”按钮下。这是工作表1上的代码,功能代码在“此工作簿”下

当我们尝试在其他worksheet_selectionchange(ByVal target As Range)代码下运行此代码时,它不允许文本框(got_focus)代码在单元格上运行。 我尝试更改代码的位置,无论是在其自己的子代码中,还是使用按钮调用该代码的位置,我都无法获取它来进行自我纠正。范围内的单元格将合并并为(“ B23:D23”),但进行此更改并没有更改我的调试错误。

Private Sub FINALIZEBTN_Click()
    Dim response As VbMsgBoxResult
    response = MsgBox("Have you completed the form in full?", vbYesNo)
    If response = vbYes Then
        MsgBox "Do not forget to save and submit this form"
    ElseIf response = vbNo Then
        MsgBox "Please review and complete the form in full"
        Exit Sub
    End If

Dim searchRange     As Excel.Range
Dim cell            As Variant
Dim RegEx           As Object

Set RegEx = CreateObject("VBScript.RegExp")

With RegEx
    .Pattern = "[^ :@a-zA-Z0-9&\-]+"
    .Global = True
    .MultiLine = True
End With

Set searchRange = ActiveSheet.Range("B18:E52") '// Change as required

    For Each cell In searchRange.Cells
        If RegEx.Test(cell) Then cell.value = RegEx.Replace(cell.value, "")
        cell.value = UCase(cell.value)
    Next cell

Set searchRange = Nothing
Set RegEx = Nothing


'ENCRYPTION MACRO

    Dim KeyCells As Range
    Set KeyCells = Range("B23")


Dim publicKey As String
    publicKey = "<RSAKeyValue><Modulus>r2+QhdQrh+jlSz/F2f9TyfVbar79NUHqiQby7paaUB5pejiYg/aI8on642s0FYNiiASSqK81+ORA9BXS0AHMnnkyplWZ7B2/KnrmFb3Ujoemzb794MpmUxtztrAocmIepJwsuShBQD2eUvCzNKI8aLcgH9mDGuG/HvagHCyzbyfV+yPtMGIHY2W1qboFGGvisAgVGjUgUAzpsqbuHiP1muohr5yKRmeyTwZmjEeWY/OuoX5zyDvjd0jsCw8GiNzkPqb6qCZR8KXSZNcyZnf4NbjR/dOD5qeEwFZWY32LmGFQW4GVOUfaIStvRwXq1G7k5oPXb6ccAhDtlrieM9l65p0X9alGYfTvLel4SBRRMqc8icadJq4KXTh1qRwp7w6uJUnd90GqfMXo1Qqyjwuqre0BBro/e3/BH8BorWynby3JAD5GNnBrB/RX9y/DFobNHXV9vtNhMTBMhCfSMhJQNlnH8nT3jcdvydbWEpNuJt3EKoCiOQlRXyv+bBL2sVTSzdCV4cWj7CfX5ZVCaliBu4nybqWOszZyQJqCHZCgnPj2Pww7wHkFUHqngiKdK6T45IkcdohLS8AU+zCUD9K6R6qTBG1S8JKkmEfuBhNx+uWMU0fwEL6ThhUmUAqZAm7MBKxnBkR+yoT5zsHoi3aYYi9sF7Opw+acqtY9zqi/OA0=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>" 'put entire xml string here

  If Not Application.Intersect(KeyCells, Range(target.Address)) Is Nothing Then
       Application.EnableEvents = False
       If VarType(Range(target.Address).value) <> 8204 Then
           If Len(Range(target.Address).value) < 256 Then 'making sure that encry sting isnt previously encrypted
              Range(target.Address).value = ThisWorkbook.Encrypt(publicKey, CStr(Range(target.Address).value))
               Range(target.Address).HorizontalAlignment = -4108 'XLALIGNCENTER
            End If
       Else
    Range(target.Address).HorizontalAlignment = -4131 'XLALIGNLEFT
        End If
       Application.EnableEvents = True
 End If
End Sub

If Not Application.Intersect(KeyCells, Range(target.Address)) Is Nothing Then导致弹出所需的运行时错误424对象。

0 个答案:

没有答案