VBA Encryption

rvinci

Board Regular
Joined
Jan 28, 2013
Messages
52
I've been trying for countless hours and I can't figure it out. I have the below code for a UserForm in Excel. Everything runs as it should except that it refuses to actually encrypt the email. Anybody able to help?

Code:
Private Sub Submit_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim VEmail As Variant
Dim TEmail As Variant
   Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    VEmail = Application.WorksheetFunction.VLookup(vendor.Value, Worksheets("Sheet1").Range("A:D"), 3, False)
    
    TEmail = Application.WorksheetFunction.VLookup(vendor.Value, Worksheets("Sheet1").Range("A:D"), 4, False)
     
    On Error Resume Next
    With OutMail
Const PR_SECURITY_FLAGS = "[URL]http://schemas.microsoft.com/mapi/proptag/0x6E010003[/URL]"
oProp = CLng(Item.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS))
Debug.Print "Original flag value is: " & oProp
If oProp = 0 Then ' checking if the mail is already encrypted
If MsgBox("This mail is not encrypted. Do you want to send the mail with auto encryption?", vbYesNo) = vbYes Then
ulFlags = 0
ulFlags = ulFlags Or &H1 ' encrypt the mail
Item.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, ulFlags
Debug.Print "Updated flag value is: " & ulFlags
End If
End If
        .To = VEmail
        .CC = TEmail
        .Subject = "C Number: " + Me.cnumber.Value + "/ R Number: " + Me.rnumber.Value + "/ B State: " + Me.bstate.Value + "/ Reason: " + Me.reason.Value
        .HTMLBody = Me.message.Value & .HTMLBody
        .Send
        

    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi, unfortuantely no :/ I have found 3 different versions of the code to encrypt an email. I tried the one above and the one that came right from Microsoft. The code runs without any issues but for some reason refuses to encrypt the email.
 
Upvote 0

Forum statistics

Threads
1,215,301
Messages
6,124,142
Members
449,144
Latest member
Rayudo125

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top